Chapter 7. Subtyping
This chapter covers
- Disambiguating types in TypeScript
- Safe deserialization
- Values for error cases
- Type compatibility for sum types, collections, and functions
Now that we’ve covered primitive types, composition, and function types, it’s time to look at another aspect of type systems: relationships between types. In this chapter, we’ll introduce the subtyping relationship. Although you may be familiar with it from object-oriented programming, we will not cover inheritance in this chapter. Instead, we will focus on a different set of applications of subtyping.
First, we’ll talk about what subtyping is and the two ways in which programming languages implement it: structural and nominal. Then we will revisit our Mars Climate ...