9 Using arrays, tuples, and enums
This chapter covers
- Restricting the types that an array can store
- Creating fixed-length arrays using tuples
- Using enums to group related values
- Using literal value types to specify a fixed set of acceptable values
- Creating a type alias to simplify working with complex type definitions
The examples so far in this part of the book have focused on primitive types, which has let me introduce the basic TypeScript features. In real projects, related data properties are grouped to create objects. In this chapter, I describe the TypeScript support for simple data structures, starting with arrays. Table 9.1 summarizes the chapter.
Problem |
Solution |
Listing |
---|---|---|
Restrict the range ... |
Get Essential TypeScript 5, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.