image of

Effective TypeScript

62 Specific Ways to Improve Your TypeScript

Dan Vanderkam

TypeScript is a typed superset of JavaScript with the potential to solve many of the headaches for which JavaScript is famous. But TypeScript has a learning curve of its own, and understanding how to use it effectively can take time. This book guides you through 62 specific ways to improve your use of TypeScript.

  • Item 1: Understand the Relationship Between TypeScript and JavaScript
  • Item 2: Know Which TypeScript Options You’re Using
  • Item 3: Understand That Code Generation is Independent of Types
  • Item 4: Get Comfortable with Structural Typing
  • Item 5: Limit the Use of any Type
  • Item 6: Use Your Editor to Interrogate and Explore the Type System
  • Item 7: Think of Types as Sets of Values
  • Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
  • Item 9: Prefer Type Declarations to Type Assertions
  • Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
  • Item 11: Recognize the Limits of Excess Property Checking
  • Item 12: Apply Types to Entire Function Expressions When Possible
  • Item 13: Know the Differences Between type and interface
  • Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
  • Item 15: Use Index Signatures for Dynamic Data
  • Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
  • Item 17: Use readonly to Avoid Errors Associated with Mutation
  • Item 18: Use Mapped Types to Keep Values in Sync (bumped to next week)
  • Item 18: Use Mapped Types to Keep Values in Sync
  • Item 19: Avoid Cluttering Your Code with Inferable Types
  • Item 20: Use Different Variables for Different Types
  • Item 21: Understand Type Widening
  • Item 22: Understand Type Narrowing
  • Item 23: Create Objects All at Once
  • Item 24: Be Consistent in Your Use of Aliases
  • Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
  • Item 26: Understand How Context Is Used In Type Inference
  • Item 27: Use Functional Constructs and Libraries to Help Types Flow
  • Item 28: Prefer Types That Always Represent Valid States
  • Item 29: Be Liberal in What You Accept and Strict in What You Produce
  • Item 30: Don’t Repeat Type Information in Documentation
  • Item 31: Push Null Values to the Perimeter of Your Types
  • Item 32: Prefer Unions of Interfaces to Interfaces of Unions
  • Item 33: Prefer More Precise Alternatives to String Types
  • Item 34: Prefer Incomplete Types to Inaccurate Types
  • Item 35: Generate Types from APIs and Specs, Not Data
  • Item 36: Name Types Using the Language of Your Problem Domain
  • Item 37: Consider “Brands” for Nominal Typing