1. Preface
    1. Who This Book Is for
    2. What’s in This Book?
    3. Conventions Used in This Book
    4. Using Code Examples
    5. O’Reilly Online Learning
    6. How to Contact Us
    7. Acknowledgments
  2. 1. Project Setup
    1. 1.1. Type-checking JavaScript
    2. 1.2. Installing TypeScript
    3. 1.3. Keeping Types on the Side
    4. 1.4. Migrating a Project to TypeScript
    5. 1.5. Loading Types from Definitely Typed
    6. 1.6. Setting up A Full-stack Project
    7. 1.7. Setting Up Tests
    8. 1.8. Typing ECMAScript Modules from URLs
    9. 1.9. Loading Different Module Types in Node
    10. 1.10. Working with Deno and Dependencies
    11. 1.11. Using Pre-defined Configurations
  3. 2. Basic Types
    1. 2.1. Annotating Effectively
    2. 2.2. Working with any and unknown
    3. 2.3. Choosing the Right Object Type
    4. 2.4. Working with Tuple Types
    5. 2.5. Understanding Interfaces vs Type Aliases
    6. 2.6. Defining Function Overloads
    7. 2.7. Defining this Parameter Types
    8. 2.8. Working with Symbols
    9. 2.9. Understanding Value and Type Namespaces
  4. 3. The Type System
    1. 3.1. Modeling Data with Union and Intersection Types
    2. 3.2. Explicitly Defining Models with Discriminated Union Types
    3. 3.3. Exhaustiveness Checking with the Assert never Technique
    4. 3.4. Pinning Types with const Context
    5. 3.5. Narrowing Types with Type Predicates
    6. 3.6. Understanding void
    7. 3.7. Dealing with Error Types in Catch Clauses
    8. 3.8. Creating Exclusive Or Models with Optional never
    9. 3.9. Effectively Using Type Assertions
    10. 3.10. Using Index Signatures
    11. 3.11. Distinguishing Missing Properties and Undefined Values
    12. 3.12. Working with Enums
    13. 3.13. Defining Nominal Types in a Structural Type System
    14. 3.14. Enabling Loose Autocomplete for String Subsets
  5. 4. Generics
    1. 4.1. Generalizing Function Signatures
    2. 4.2. Creating Related Function Arguments
    3. 4.3. Getting Rid of any and unknown
    4. 4.4. Understanding Generic Instantiation
    5. 4.5. Generating New Object Types
    6. 4.6. Modifying Objects with Assertion Signatures
    7. 4.7. Mapping Types with Type Maps
    8. 4.8. Using ThisType to Define this in Objects
    9. 4.9. Adding const Context to Generic Type Parameters
  6. 5. Conditional Types
    1. 5.1. Managing Complex Function Signatures
    2. 5.2. Filtering with never
    3. 5.3. Grouping Elements by Kind
    4. 5.4. Removing Specific Object Properties
    5. 5.5. Inferring Types in Conditionals
  7. 6. String Template Literal Types
    1. 6.1. Defining a Custom Event System
    2. 6.2. Creating Event Callbacks with String Manipulation Types and Key Re-Mapping
    3. 6.3. Writing a Formatter Function
    4. 6.4. Extracting Format Parameter Types
    5. 6.5. Dealing with Recursion Limits
    6. 6.6. Using Template Literals as Discriminants
  8. 7. Variadic Tuple Types
    1. 7.1. Typing a concat Function
    2. 7.2. Typing a promisify Function
    3. 7.3. Typing a curry Function
    4. 7.4. Typing a Flexible curry Function
    5. 7.5. Typing the Simplest curry function
    6. 7.6. Creating an Enum from a Tuple
    7. 7.7. Splitting All Elements of a Function Signature
  9. 8. Helper Types
    1. 8.1. Setting Specific Properties Optional
    2. 8.2. Modifying Nested Objects
    3. 8.3. Remapping Types
    4. 8.4. Getting All Required keys
    5. 8.5. Allowing at Least One Property
    6. 8.6. Allowing Exactly One and All Or None
    7. 8.7. Converting Union To Intersection Types
    8. 8.8. Using type-fest
  10. 9. The Standard Library and External Type Definitions
    1. 9.1. Iterating over Objects with Object.keys
    2. 9.2. Explicitly Highlighting Unsafe Operations with Type Assertions and unknown
    3. 9.3. Working with defineProperty
    4. 9.4. Expanding Types for Array.prototype.includes
    5. 9.5. Filtering Nullish Values
    6. 9.6. Extending Modules
    7. 9.7. Augmenting Globals
    8. 9.8. Adding Non-JS Modules to the Module Graph
  11. 10. TypeScript and React
    1. 10.1. Writing Proxy Components
    2. 10.2. Writing Controlled Components
    3. 10.3. Typing Custom Hooks
    4. 10.4. Typing Generic forwardRef Components
    5. 10.5. Providing Types for the Context API
    6. 10.6. Typing Higher Order Components
    7. 10.7. Typing Callbacks in React’s Synthetic Event System
    8. 10.8. Typing Polymorphic Components
  12. 11. Classes
    1. 11.1. Choosing the Right Visibility Modifier
    2. 11.2. Explicitly Defining Method Overrides
    3. 11.3. Describing Constructors and Prototypes
    4. 11.4. Using Generics in Classes
    5. 11.5. Deciding When to Use Classes or Namespaces
    6. 11.6. Writing Static Classes
    7. 11.7. Working with Strict Property Initialization
    8. 11.8. Working with this Types in Classes
    9. 11.9. Writing Decorators
  13. 12. Type Development Strategies
    1. 12.1. Writing Low Maintenance Types
    2. 12.2. Refining Types Step by Step
    3. 12.3. Checking Contracts with satisfies
    4. 12.4. Testing Complex Types
    5. 12.5. Validating Data Types at Runtime with Zod
    6. 12.6. Working Around Index Access Restrictions
    7. 12.7. Deciding Whether to Use Function Overloads or Conditional Types
    8. 12.8. Naming Generics
    9. 12.9. Prototyping on the TypeScript Playground
    10. 12.10. Providing Multiple Library Versions
    11. 12.11. Knowing When to Stop
  14. About the Author