effective-typescript
-
Second Edition
Latest Release
Published by danvk 5 months ago
Released May 2024.
- 📖 New Chapters:
- Chapter 6: Generics and Type-Level Programming
- Chapter 7: TypeScript Recipes
- ➕ New Items
-
Item 28: Use Classes and Currying to Create New Inference Sites
-
Item 32: Avoid Including null or undefined in Type Aliases
-
Item 36: Use a Distinct Type for Special Values
-
Item 37: Limit the Use of Optional Properties
-
Item 38: Avoid Repeated Parameters of the Same Type
-
Item 39: Prefer Unifying Types to Modeling Differences
-
Item 48: Avoid Soundness Traps
-
Item 50: Think of Generics as Functions Between Types
-
Item 51: Avoid Unnecessary Type Parameters
-
Item 53: Know how to Control the Distribution of Unions over Conditional Types
-
Item 54: Use Template Literal Types to Model DSLs and Relationships Between Strings
-
Item 56: Pay Attention to how Types Display
-
Item 57: Prefer Tail-Recursive Generic Types
-
Item 58: Consider Codegen As an Alternative to Complex Types
-
Item 59: Use Never Types to Perform Exhaustiveness Checking
-
Item 62: Use Rest Parameters and Tuple Types to Model Variadic Functions
-
Item 63: Use Optional Never Properties to Model Exclusive Or
-
Item 71: Use Module Augmentation to Improve Types
-
Item 74: Know How to Reconstruct Types at Runtime
-
Item 76: Create an Accurate Model of Your Environment
-
Item 77: Understand the Relationship Between Type Checking and Unit Testing
-
Item 78: Pay Attention to Compiler Performance
- ➖ Dropped Items
- Item 56: Don't Rely on Private to Hide Information
- 🚧 Items with Major Changes
-
Item 13: Know the Differences Between type and interface
-
Item 14: Use readonly to Avoid Errors Associated with Mutation (was Item 17)
-
Item 15: Use Type Operations and Generic Types to Avoid Repeating Yourself (was Item 14: Use Type Operations and Generics to Avoid Repeating Yourself)
-
Item 16: Prefer More Precise Alternatives to Index Signatures (was Item 15: Use Index Signatures for Dynamic Data)
-
Item 17: Avoid Numeric Index Signatures (was Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures)
-
Item 20: Understand How a Variable Gets Its Type (was Item 21: Understand Type Widening)
-
Item 42: Avoid Types Based on Anecdotal Data (was Item 35: Generate Types from APIs and Specs, Not Data)
-
Item 45: Hide Unsafe Type Assertions in Well-Typed Functions (was Item 40)
-
Item 47: Prefer Type-Safe Approaches to Monkey Patching (was Item 43)
-
Item 55: Write Tests for Your Types (was Item 52: Be Aware of the Pitfalls of Testing Types)
-
Item 70: Mirror Types to Sever Dependencies (was Item 51)
-
Item 72: Prefer ECMAScript Features to TypeScript Features (was Item 53)
-
Item 73: Use Source Maps to Debug TypeScript (was Item 57)
-
Item 79: Write Modern JavaScript (was Item 58)
- ✏️ Items with Minor Changes
-
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 Use of the 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 Annotations to Type Assertions (was Item 9: Prefer Type Declarations to Type Assertions)
-
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Item 11: Distinguish Excess Property Checking from Type Checking (was Item 11: Recognize the Limits of Excess Property Checking)
-
Item 12: Apply Types to Entire Function Expressions When Possible
-
Item 18: Avoid Cluttering Your Code with Inferable Types (was Item 19)
-
Item 19: Use Different Variables for Different Types (was Item 20)
-
Item 21: Create Objects All at Once (was Item 23)
-
Item 22: Understand Type Narrowing
-
Item 23: Be Consistent in Your Use of Aliases (was Item 24)
-
Item 24: Understand How Context Is Used in Type Inference (was Item 26)
-
Item 25: Understand Evolving Types (was Item 41: Understand Evolving any)
-
Item 26: Use Functional Constructs and Libraries to Help Types Flow (was Item 27)
-
Item 27: Use async Functions Instead of Callbacks to Improve Type Flow (was Item 25: Use async Functions Instead of Callbacks for Asynchronous Code)
-
Item 29: Prefer Types That Always Represent Valid States (was Item 28)
-
Item 30: Be Liberal in What You Accept and Strict in What You Produce (was Item 29)
-
Item 31: Don’t Repeat Type Information in Documentation (was Item 30)
-
Item 33: Push Null Values to the Perimeter of Your Types (was Item 31)
-
Item 34: Prefer Unions of Interfaces to Interfaces with Unions (was Item 32: Prefer Unions of Interfaces to Interfaces of Unions)
-
Item 35: Prefer More Precise Alternatives to String Types (was Item 33)
-
Item 40: Prefer Imprecise Types to Inaccurate Types (was Item 34: Prefer Incomplete Types to Inaccurate Types)
-
Item 41: Name Types Using the Language of Your Problem Domain (was Item 36)
-
Item 43: Use the Narrowest Possible Scope for any Types (was Item 38)
-
Item 44: Prefer More Precise Variants of any to Plain any (was Item 39)
-
Item 46: Use unknown Instead of any for Values with an Unknown Type (was Item 42)
-
Item 49: Track Your Type Coverage to Prevent Regressions in Type Safety (was Item 44)
-
Item 52: Prefer Conditional Types to Overload Signatures (was Item 50: Prefer Conditional Types to Overloaded Declarations)
-
Item 60: Know How to Iterate Over Objects (was Item 54)
-
Item 61: Use Record Types to Keep Values in Sync (was Item 18: Use Mapped Types to Keep Values in Sync)
-
Item 64: Consider "Brands" for Nominal Typing (was Item 37)
-
Item 65: Put TypeScript and @types in devDependencies (was Item 45)
-
Item 66: Understand the Three Versions Involved in Type Declarations (was Item 46)
-
Item 67: Export All Types That Appear in Public APIs (was Item 47)
-
Item 68: Use TSDoc for API Comments (was Item 48)
-
Item 69: Provide a Type for this in Callbacks if it's part of their API (was Item 49: Provide a Type for this in Callbacks)
-
Item 75: Understand the DOM hierarchy (was Item 55)
-
Item 80: Use @ts-check and JSDoc to Experiment with TypeScript (was Item 59)
-
Item 81: Use allowJs to Mix TypeScript and JavaScript (was Item 60)
-
Item 82: Convert Module by Module Up Your Dependency Graph (was Item 61)
-
Item 83: Don't Consider Migration Complete Until You Enable noImplicitAny (was Item 62)