Home Page Icon
Home Page
Table of Contents for
Index
Close
Index
by Dan Vanderkam
Effective TypeScript
Preface
Who This Book Is For
Why I Wrote This Book
How This Book Is Organized
Conventions in TypeScript Code Samples
Typographical Conventions Used in This Book
Using Code Examples
O’Reilly Online Learning
How to Contact Us
Acknowledgments
1. Getting to Know 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 Use of the any Type
2. TypeScript’s Type System
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
3. Type Inference
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
4. Type Design
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
5. Working with any
Item 38: Use the Narrowest Possible Scope for any Types
Item 39: Prefer More Precise Variants of any to Plain any
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
Item 41: Understand Evolving any
Item 42: Use unknown Instead of any for Values with an Unknown Type
Item 43: Prefer Type-Safe Approaches to Monkey Patching
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
6. Types Declarations and @types
Item 45: Put TypeScript and @types in devDependencies
Item 46: Understand the Three Versions Involved in Type Declarations
Item 47: Export All Types That Appear in Public APIs
Item 48: Use TSDoc for API Comments
Item 49: Provide a Type for this in Callbacks
Item 50: Prefer Conditional Types to Overloaded Declarations
Item 51: Mirror Types to Sever Dependencies
Item 52: Be Aware of the Pitfalls of Testing Types
7. Writing and Running Your Code
Item 53: Prefer ECMAScript Features to TypeScript Features
Item 54: Know How to Iterate Over Objects
Item 55: Understand the DOM hierarchy
Item 56: Don’t Rely on Private to Hide Information
Item 57: Use Source Maps to Debug TypeScript
8. Migrating to TypeScript
Item 58: Write Modern JavaScript
Item 59: Use @ts-check and JSDoc to Experiment with TypeScript
Item 60: Use allowJs to Mix TypeScript and JavaScript
Item 61: Convert Module by Module Up Your Dependency Graph
Item 62: Don’t Consider Migration Complete Until You Enable noImplicitAny
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
8. Migrating to TypeScript
Next
Next Chapter
About the Author
Index
Symbols
! operator
,
Item 9: Prefer Type Declarations to Type Assertions
# (private field prefix)
,
Item 56: Don’t Rely on Private to Hide Information
& operator
,
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
() => any
,
Item 39: Prefer More Precise Variants of any to Plain any
-
Things to Remember
.js/.jsx extension
,
Item 1: Understand the Relationship Between TypeScript and JavaScript
.ts/.tsx extension
,
Item 1: Understand the Relationship Between TypeScript and JavaScript
@param type
,
Item 48: Use TSDoc for API Comments
@returns type
,
Item 48: Use TSDoc for API Comments
@ts-check
,
Item 59: Use @ts-check and JSDoc to Experiment with TypeScript
-
Things to Remember
@ts-ignore
,
Item 38: Use the Narrowest Possible Scope for any Types
@types (type dependencies)
installing in devDependencies
,
Item 45: Put TypeScript and @types in devDependencies
JavaScript developers and
,
Item 51: Mirror Types to Sever Dependencies
preventing regressions in type safety
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
three versions involved in
,
Item 46: Understand the Three Versions Involved in Type Declarations
-
Things to Remember
[ ] property accessor
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
{ } type
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
-
Things to Remember
{[id: string]: any}
,
Item 39: Prefer More Precise Variants of any to Plain any
-
Things to Remember
{[key: string]: any} type
,
Item 39: Prefer More Precise Variants of any to Plain any
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
| operator
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
A
aliases
,
Item 24: Be Consistent in Your Use of Aliases
-
Things to Remember
allowJs
,
Item 60: Use allowJs to Mix TypeScript and JavaScript
Angular
,
Decorators
any types
drawbacks of
,
Item 5: Limit Use of the any Type
-
Things to Remember
evolving
,
Item 41: Understand Evolving any
-
Things to Remember
hiding unsafe type assertions
,
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
versus inaccurate models
,
Item 33: Prefer More Precise Alternatives to String Types
plain any versus more precise variants
,
Item 39: Prefer More Precise Variants of any to Plain any
-
Things to Remember
preventing regressions in type safety
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
type-safe approaches versus monkey-patching
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
unknown versus any types
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
-
Things to Remember
using narrow scope for
,
Item 38: Use the Narrowest Possible Scope for any Types
-
Things to Remember
any[ ] types
,
Item 39: Prefer More Precise Variants of any to Plain any
-
Things to Remember
,
Item 41: Understand Evolving any
-
Things to Remember
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
Array interface
,
Item 13: Know the Differences Between type and interface
array methods
,
Use for-of or Array Methods Instead of for(;;)
Array type
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
ArrayLike type
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
arrays
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
arrow functions
,
Item 9: Prefer Type Declarations to Type Assertions
,
Prefer Arrow Functions Over Function Expressions
as const
,
Item 21: Understand Type Widening
,
Objects
assignable to
,
Item 7: Think of Types as Sets of Values
,
Item 52: Be Aware of the Pitfalls of Testing Types
,
Item 54: Know How to Iterate Over Objects
Astaire, Fred
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
async arrow functions
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
async functions
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
-
Things to Remember
async/await
,
Use async/await Instead of Raw Promises or Callbacks
asynchronous code
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
-
Things to Remember
augmentation
,
Item 13: Know the Differences Between type and interface
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
await keyword
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
-
Things to Remember
,
Use async/await Instead of Raw Promises or Callbacks
B
bigint primitive
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
boolean primitives
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
brands
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
Brooks, Fred
,
Type Design
,
Item 28: Prefer Types That Always Represent Valid States
browserify
,
Item 60: Use allowJs to Mix TypeScript and JavaScript
built-in types, storing data on
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
bundling types
,
Item 46: Understand the Three Versions Involved in Type Declarations
C
C++
,
You Cannot Overload a Function Based on TypeScript Types
,
Item 4: Get Comfortable with Structural Typing
,
Type Inference
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
callbacks
async functions versus callbacks
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
-
Things to Remember
versus async/await
,
Use async/await Instead of Raw Promises or Callbacks
ECMAScript modules
,
Use ECMAScript Modules
providing types for this keyword in
,
Item 49: Provide a Type for this in Callbacks
testing inferred types
,
Item 52: Be Aware of the Pitfalls of Testing Types
type declarations for
,
Item 12: Apply Types to Entire Function Expressions When Possible
type inference and
,
Callbacks
class construct
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
classes
ES2015
,
Use Classes Instead of Prototypes
implements
,
Item 13: Know the Differences Between type and interface
nominal typing
,
Item 37: Consider “Brands” for Nominal Typing
parameter properties
,
Parameter Properties
private fields
,
Item 56: Don’t Rely on Private to Hide Information
this
,
Parameter Properties
type versus value
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
classes, versus prototypes
,
Use Classes Instead of Prototypes
Closure Compiler
,
Inaccurate JSDoc
closures
,
Item 56: Don’t Rely on Private to Hide Information
code generation, independent of types
,
Item 3: Understand That Code Generation Is Independent of Types
-
Things to Remember
code samples, conventions used in
,
Conventions in TypeScript Code Samples
code, writing and running
debugging with source maps
,
Item 57: Use Source Maps to Debug TypeScript
-
Things to Remember
DOM hierarchy
,
Item 55: Understand the DOM hierarchy
-
Things to Remember
ECMAScript versus TypeScript features
,
Item 53: Prefer ECMAScript Features to TypeScript Features
-
Things to Remember
hiding information
,
Item 56: Don’t Rely on Private to Hide Information
iterating over objects
,
Item 54: Know How to Iterate Over Objects
compact object literals
,
Use Compact Object Literals and Destructuring Assignment
compiling
compiler options
,
Item 2: Know Which TypeScript Options You’re Using
,
Prefer Arrow Functions Over Function Expressions
,
Don’t Put use strict in TypeScript
,
Item 60: Use allowJs to Mix TypeScript and JavaScript
compiling versus type checking
,
Code with Type Errors Can Produce Output
-
Things to Remember
in TypeScript
,
Getting to Know TypeScript
conditional types
,
Item 50: Prefer Conditional Types to Overloaded Declarations
configuration settings
,
Item 2: Know Which TypeScript Options You’re Using
-
Things to Remember
const
avoiding errors associated with mutation
,
Item 17: Use readonly to Avoid Errors Associated with Mutation
-
Things to Remember
const versus as const
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
need for context
,
Item 21: Understand Type Widening
type declarations and
,
Tuple Types
const assertion
,
Item 21: Understand Type Widening
,
Objects
context
,
Item 21: Understand Type Widening
,
Item 26: Understand How Context Is Used in Type Inference
-
Things to Remember
contracts, breaking with any type
,
any Lets You Break Contracts
CSV
,
Item 15: Use Index Signatures for Dynamic Data
-
Things to Remember
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
,
Item 51: Mirror Types to Sever Dependencies
Curie, Marie
,
Use Classes Instead of Prototypes
Curry, Stephen
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
D
Davis, Miles
,
Item 33: Prefer More Precise Alternatives to String Types
debugging
any type drawbacks
,
any Types Mask Bugs When You Refactor Code
with source maps
,
Item 57: Use Source Maps to Debug TypeScript
-
Things to Remember
declaration merging
,
Item 13: Know the Differences Between type and interface
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
declared types
,
Runtime Types May Not Be the Same as Declared Types
decorators
,
Decorators
DefinitelyTyped
,
Item 45: Put TypeScript and @types in devDependencies
,
Item 46: Understand the Three Versions Involved in Type Declarations
dependencies
,
Item 45: Put TypeScript and @types in devDependencies
destructuring assignment
,
Use Compact Object Literals and Destructuring Assignment
devDependencies
,
Item 45: Put TypeScript and @types in devDependencies
discriminated unions
(
see
tagged unions)
documentation, type information in
,
Item 30: Don’t Repeat Type Information in Documentation
DOM hierarchy
,
Item 55: Understand the DOM hierarchy
-
Things to Remember
,
DOM Issues
domain of a type
,
Item 7: Think of Types as Sets of Values
-
Things to Remember
double assertion
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
DRY (don’t repeat yourself) principle
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
-
Things to Remember
dtslint
,
Item 52: Be Aware of the Pitfalls of Testing Types
,
Item 52: Be Aware of the Pitfalls of Testing Types
duck typing
,
Item 4: Get Comfortable with Structural Typing
-
Things to Remember
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
dygraph.js
,
Undeclared Class Members
dynamic data
,
Item 15: Use Index Signatures for Dynamic Data
-
Things to Remember
E
ECMAScript
,
Item 53: Prefer ECMAScript Features to TypeScript Features
-
Things to Remember
,
Use ECMAScript Modules
editors, using to interrogate and explore type system
,
Item 6: Use Your Editor to Interrogate and Explore the Type System
-
Things to Remember
Element
,
Item 55: Understand the DOM hierarchy
enums (enumerations)
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
,
Enums
equality
,
Item 52: Be Aware of the Pitfalls of Testing Types
ES2015
class keyword
,
Use Classes Instead of Prototypes
Convert function
,
Use Classes Instead of Prototypes
keys in
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
merging and
,
Item 13: Know the Differences Between type and interface
Promises in
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
symbol primitive
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
writing modern JavaScript
,
Item 58: Write Modern JavaScript
ES2017
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
,
Item 56: Don’t Rely on Private to Hide Information
ES5
async and await in
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
generator functions
,
TypeScript Types Have No Effect on Runtime Performance
merging and
,
Item 13: Know the Differences Between type and interface
numeric keys and
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
strict mode
,
Don’t Put use strict in TypeScript
eslint
,
Item 19: Avoid Cluttering Your Code with Inferable Types
Event
,
Item 55: Understand the DOM hierarchy
EventTarget
,
Item 55: Understand the DOM hierarchy
evolving any
,
Item 41: Understand Evolving any
-
Things to Remember
excess property checking
limits of
,
Item 11: Recognize the Limits of Excess Property Checking
-
Things to Remember
type declaration and
,
Item 9: Prefer Type Declarations to Type Assertions
explicitly typed languages
,
Type Inference
extends
,
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 14: Use Type Operations and Generics to Avoid Repeating Yourself
F
flatMap
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
for(;;)
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
,
Use for-of or Array Methods Instead of for(;;)
for-in loops
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
,
Item 54: Know How to Iterate Over Objects
for-of
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
,
Use for-of or Array Methods Instead of for(;;)
function expressions
,
Prefer Arrow Functions Over Function Expressions
functions
applying type annotations to function expressions
,
Item 12: Apply Types to Entire Function Expressions When Possible
-
Things to Remember
arrow functions
,
Item 9: Prefer Type Declarations to Type Assertions
,
Prefer Arrow Functions Over Function Expressions
avoid returning any types from
,
Item 38: Use the Narrowest Possible Scope for any Types
-
Things to Remember
default function parameters
,
Use Default Function Parameters
hiding unsafe type assertions in
,
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
inspecting with editors
,
Item 6: Use Your Editor to Interrogate and Explore the Type System
overloading
,
You Cannot Overload a Function Based on TypeScript Types
robustness principle
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
-
Things to Remember
testing inferred types of callbacks
,
Item 52: Be Aware of the Pitfalls of Testing Types
utility libraries versus hand-rolled
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
-
Things to Remember
G
generic types
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
GeoJSON
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
,
Item 34: Prefer Incomplete Types to Inaccurate Types
-
Item 34: Prefer Incomplete Types to Inaccurate Types
,
Item 35: Generate Types from APIs and Specs, Not Data
-
Things to Remember
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
Geometry
,
Item 34: Prefer Incomplete Types to Inaccurate Types
,
Item 35: Generate Types from APIs and Specs, Not Data
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
global variables
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
,
Undeclared Globals
Griffin, Blake
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
H
Hejlsberg, Anders
,
Item 26: Understand How Context Is Used in Type Inference
Hopper, Grace
,
Item 59: Use @ts-check and JSDoc to Experiment with TypeScript
HTMLElement
,
Item 55: Understand the DOM hierarchy
I
implicit anys
,
Item 2: Know Which TypeScript Options You’re Using
in construct
in (for-in)
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
,
Item 54: Know How to Iterate Over Objects
in (mapped type)
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
,
Item 15: Use Index Signatures for Dynamic Data
,
Item 18: Use Mapped Types to Keep Values in Sync
-
Things to Remember
value versus type space meanings
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
index signatures
versus arrays, tuples, and ArrayLike
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
-
Things to Remember
for dynamic data
,
Item 15: Use Index Signatures for Dynamic Data
-
Things to Remember
readonly and
,
Item 17: Use readonly to Avoid Errors Associated with Mutation
indexing
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
inferable types
,
Item 19: Avoid Cluttering Your Code with Inferable Types
-
Things to Remember
inferringPick
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
interface construct
as alternative to index signatures
,
Item 15: Use Index Signatures for Dynamic Data
existence in type space
,
Things to Remember
type versus interface
,
Item 13: Know the Differences Between type and interface
-
Things to Remember
unions of interfaces versus interfaces of unions
,
Item 32: Prefer Unions of Interfaces to Interfaces of Unions
-
Things to Remember
invalid states
,
Item 28: Prefer Types That Always Represent Valid States
-
Things to Remember
J
James, LeBron
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
Java
addition of var
,
Type Inference
declaring parameters in
,
Item 4: Get Comfortable with Structural Typing
hashable objects in
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
rewriting code in
,
Item 1: Understand the Relationship Between TypeScript and JavaScript
standard libraries in
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
String objects
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
type checking and output in
,
Code with Type Errors Can Produce Output
versus TypeScript
,
Getting to Know TypeScript
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
JavaScript
duck typing
,
Item 4: Get Comfortable with Structural Typing
-
Things to Remember
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
function statements versus function expressions
,
Item 12: Apply Types to Entire Function Expressions When Possible
implicit type coercions in
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
migrating to TypeScript
,
Item 1: Understand the Relationship Between TypeScript and JavaScript
,
Migrating to TypeScript
-
Things to Remember
mixing with TypeScript
,
Item 60: Use allowJs to Mix TypeScript and JavaScript
objects in
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
open classes in
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
relationship to TypeScript
,
Item 1: Understand the Relationship Between TypeScript and JavaScript
-
Things to Remember
,
Item 53: Prefer ECMAScript Features to TypeScript Features
this keyword
,
Item 49: Provide a Type for this in Callbacks
,
Prefer Arrow Functions Over Function Expressions
writing modern
,
Item 58: Write Modern JavaScript
-
Things to Remember
jQuery
dependencies
,
Item 45: Put TypeScript and @types in devDependencies
interacting with DOM
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
type declarations for
,
Unknown Libraries
type-safe approaches versus monkey-patching
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
JSDoc-style comments
,
Item 48: Use TSDoc for API Comments
,
Item 59: Use @ts-check and JSDoc to Experiment with TypeScript
-
Things to Remember
JSON
,
Item 12: Apply Types to Entire Function Expressions When Possible
,
Item 34: Prefer Incomplete Types to Inaccurate Types
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
K
Karlton, Phil
,
Item 36: Name Types Using the Language of Your Problem Domain
keyof
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
keyof T
,
Item 33: Prefer More Precise Alternatives to String Types
L
language services
commenting convention supported by
,
Item 48: Use TSDoc for API Comments
components of
,
Item 6: Use Your Editor to Interrogate and Explore the Type System
drawbacks of any types
,
There Are No Language Services for any Types
navigating libraries and type declarations
,
Item 6: Use Your Editor to Interrogate and Explore the Type System
let k: keyof T
,
Item 54: Know How to Iterate Over Objects
let/const
,
Use let/const Instead of var
libraries
navigating libraries and type declarations
,
Item 6: Use Your Editor to Interrogate and Explore the Type System
unknown third-party
,
Unknown Libraries
using utility libraries
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
-
Things to Remember
Lodash library
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
-
Things to Remember
,
Item 45: Put TypeScript and @types in devDependencies
-
Item 46: Understand the Three Versions Involved in Type Declarations
,
Item 52: Be Aware of the Pitfalls of Testing Types
,
Item 52: Be Aware of the Pitfalls of Testing Types
M
Mapbox library
,
Item 34: Prefer Incomplete Types to Inaccurate Types
,
Item 34: Prefer Incomplete Types to Inaccurate Types
mapped types
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
,
Item 15: Use Index Signatures for Dynamic Data
,
Item 18: Use Mapped Types to Keep Values in Sync
-
Things to Remember
migration
converting module by module
,
Item 61: Convert Module by Module Up Your Dependency Graph
-
Things to Remember
experimenting with TypeScript
,
Item 59: Use @ts-check and JSDoc to Experiment with TypeScript
-
Things to Remember
mixing TypeScript with JavaScript
,
Item 60: Use allowJs to Mix TypeScript and JavaScript
noImplicitAny
,
Item 62: Don’t Consider Migration Complete Until You Enable noImplicitAny
overview of
,
Migrating to TypeScript
writing modern JavaScript
,
Item 58: Write Modern JavaScript
-
Things to Remember
MouseEvent
,
Item 55: Understand the DOM hierarchy
mutations, avoiding errors associated with
,
Item 17: Use readonly to Avoid Errors Associated with Mutation
-
Things to Remember
N
named types
,
Item 33: Prefer More Precise Alternatives to String Types
names and naming
,
Item 36: Name Types Using the Language of Your Problem Domain
-
Things to Remember
namespace
triple-slash imports and
,
Namespaces and Triple-Slash Imports
type declarations and
,
Item 46: Understand the Three Versions Involved in Type Declarations
narrowing
,
Item 22: Understand Type Narrowing
never type
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
Node
,
Item 55: Understand the DOM hierarchy
Node Package Manager (npm), dependency distinctions in
,
Item 45: Put TypeScript and @types in devDependencies
NodeJS
,
Item 51: Mirror Types to Sever Dependencies
noImplicitAny
,
Item 2: Know Which TypeScript Options You’re Using
-
Things to Remember
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
,
Item 62: Don’t Consider Migration Complete Until You Enable noImplicitAny
noImplicitThis
,
Item 2: Know Which TypeScript Options You’re Using
,
Prefer Arrow Functions Over Function Expressions
nominal typing
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
non-null assertions
,
Item 9: Prefer Type Declarations to Type Assertions
non-null values
,
Item 31: Push Null Values to the Perimeter of Your Types
-
Things to Remember
null primitive
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
null values
,
Item 31: Push Null Values to the Perimeter of Your Types
-
Things to Remember
number primitives
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
O
object spread operator (…)
,
Item 23: Create Objects All at Once
object type
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
-
Things to Remember
object wrapper types
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
Object.entries
,
Item 54: Know How to Iterate Over Objects
Object.keys
,
Item 4: Get Comfortable with Structural Typing
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
,
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
Object.values
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
objects
compact object literals
,
Use Compact Object Literals and Destructuring Assignment
creating all at once
,
Item 23: Create Objects All at Once
-
Things to Remember
iterating over
,
Item 54: Know How to Iterate Over Objects
in JavaScript
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
type inference and
,
Objects
overloaded declarations
,
Item 50: Prefer Conditional Types to Overloaded Declarations
overloading functions
,
You Cannot Overload a Function Based on TypeScript Types
P
parameter properties
,
Parameter Properties
parameter types
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
Partial type
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
Paul, Chris
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
Pick type
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
Postel's Law
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
-
Things to Remember
private field modifier
,
Item 56: Don’t Rely on Private to Hide Information
Promises
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
-
Things to Remember
,
Item 31: Push Null Values to the Perimeter of Your Types
,
Use async/await Instead of Raw Promises or Callbacks
properties
attaching to built-in types
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
modeling outside of type system
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
naming
,
Item 36: Name Types Using the Language of Your Problem Domain
-
Things to Remember
parameter properties
,
Parameter Properties
property checking
,
Things to Remember
protected field modifier
,
Item 56: Don’t Rely on Private to Hide Information
prototype pollution
,
Item 54: Know How to Iterate Over Objects
prototypes
,
Use Classes Instead of Prototypes
public APIs
exporting all types appearing in
,
Item 47: Export All Types That Appear in Public APIs
TSDoc for API comments
,
Item 48: Use TSDoc for API Comments
public field modifier
,
Item 56: Don’t Rely on Private to Hide Information
R
Ramda library
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
,
Item 46: Understand the Three Versions Involved in Type Declarations
React library
dependencies
,
Item 45: Put TypeScript and @types in devDependencies
-
Item 46: Understand the Three Versions Involved in Type Declarations
DOM hierarchy and
,
Item 55: Understand the DOM hierarchy
optimizations in
,
Item 18: Use Mapped Types to Keep Values in Sync
Person in
,
Item 9: Prefer Type Declarations to Type Assertions
useMemo hook
,
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
readonly
,
Item 17: Use readonly to Avoid Errors Associated with Mutation
-
Things to Remember
Records
,
Item 15: Use Index Signatures for Dynamic Data
recursive types
,
Item 34: Prefer Incomplete Types to Inaccurate Types
repetition, avoiding
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
-
Things to Remember
return types
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
ReturnType
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
robustness principle
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
-
Things to Remember
Rogers, Ginger
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
runtime
effect of TypeScript types on performance
,
TypeScript Types Have No Effect on Runtime Performance
inability to check TypeScript at
,
You Cannot Check TypeScript Types at Runtime
runtime types versus declared types
,
Runtime Types May Not Be the Same as Declared Types
type operations and runtime values
,
Type Operations Cannot Affect Runtime Values
S
security
,
Item 56: Don’t Rely on Private to Hide Information
Shelley, Mary
,
Item 17: Use readonly to Avoid Errors Associated with Mutation
source maps
,
Item 57: Use Source Maps to Debug TypeScript
-
Things to Remember
statically typed languages
,
Type Inference
strict mode
,
Don’t Put use strict in TypeScript
strictNullChecks
,
Item 2: Know Which TypeScript Options You’re Using
-
Things to Remember
,
Item 31: Push Null Values to the Perimeter of Your Types
-
Things to Remember
string primitives
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
string types, alternatives to
,
Item 33: Prefer More Precise Alternatives to String Types
-
Things to Remember
structural typing
,
Item 4: Get Comfortable with Structural Typing
-
Things to Remember
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
,
Item 51: Mirror Types to Sever Dependencies
subsets
,
Item 7: Think of Types as Sets of Values
subtypes
,
Item 7: Think of Types as Sets of Values
symbols
symbol primitives
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
type space versus value space
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
-
Things to Remember
T
tagged unions
example of
,
You Cannot Check TypeScript Types at Runtime
,
Item 22: Understand Type Narrowing
querying at runtime using
,
Things to Remember
unions of interfaces versus interfaces of unions
,
Item 32: Prefer Unions of Interfaces to Interfaces of Unions
-
Things to Remember
TC39
,
Things to Remember
test-driven development (TDD)
,
Item 19: Avoid Cluttering Your Code with Inferable Types
Testing types
,
Item 52: Be Aware of the Pitfalls of Testing Types
-
Things to Remember
third-party type declarations
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
this keyword
,
Item 49: Provide a Type for this in Callbacks
,
Prefer Arrow Functions Over Function Expressions
this operator
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
transpiling
,
Item 3: Understand That Code Generation Is Independent of Types
(
see also
compiling)
triple-slash imports
,
Namespaces and Triple-Slash Imports
Truth, Sojourner
,
Item 19: Avoid Cluttering Your Code with Inferable Types
ts-node
,
Use ECMAScript Modules
tsconfig.json
experimentalDecorators property
,
Decorators
knowing which options you’re using
,
Item 2: Know Which TypeScript Options You’re Using
-
Code with Type Errors Can Produce Output
merging and
,
Item 13: Know the Differences Between type and interface
noImplicitAny
,
Item 62: Don’t Consider Migration Complete Until You Enable noImplicitAny
sourceMap option
,
Item 57: Use Source Maps to Debug TypeScript
TSDoc
,
Item 48: Use TSDoc for API Comments
tuple type
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
,
Tuple Types
Turing, Alan
,
Item 7: Think of Types as Sets of Values
,
Item 32: Prefer Unions of Interfaces to Interfaces of Unions
Twain, Mark
,
Item 12: Apply Types to Entire Function Expressions When Possible
type annotations
avoiding cluttered code
,
Item 19: Avoid Cluttering Your Code with Inferable Types
-
Things to Remember
reducing need for
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
-
Things to Remember
using explicit with any types
,
Item 38: Use the Narrowest Possible Scope for any Types
,
Item 41: Understand Evolving any
-
Things to Remember
using more effectively
,
Item 21: Understand Type Widening
type assertion
example of
,
Type Operations Cannot Affect Runtime Values
hiding unsafe type assertions
,
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
misuse of
,
Item 5: Limit Use of the any Type
versus type declarations
,
Item 9: Prefer Type Declarations to Type Assertions
-
Things to Remember
type checking, versus excess property checking
,
Item 11: Recognize the Limits of Excess Property Checking
type construct
,
Item 13: Know the Differences Between type and interface
-
Things to Remember
type declaration
conditional types versus overloaded declarations
,
Item 50: Prefer Conditional Types to Overloaded Declarations
mirroring types to sever dependencies
,
Item 51: Mirror Types to Sever Dependencies
navigating with language services
,
Item 6: Use Your Editor to Interrogate and Explore the Type System
pitfalls of testing types
,
Item 52: Be Aware of the Pitfalls of Testing Types
providing types for this keyword in callbacks
,
Item 49: Provide a Type for this in Callbacks
third-party
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
three versions involved in
,
Item 46: Understand the Three Versions Involved in Type Declarations
-
Things to Remember
TSDoc for API comments
,
Item 48: Use TSDoc for API Comments
versus type assertion
,
Item 9: Prefer Type Declarations to Type Assertions
-
Things to Remember
types in public APIs
,
Item 47: Export All Types That Appear in Public APIs
TypeScript and @types
,
Item 45: Put TypeScript and @types in devDependencies
type dependencies
(
see
@types)
type design
alternatives to string types
,
Item 33: Prefer More Precise Alternatives to String Types
-
Things to Remember
any type drawbacks
,
any Hides Your Type Design
generating types from specifications
,
Item 35: Generate Types from APIs and Specs, Not Data
-
Things to Remember
incomplete versus inaccurate types
,
Item 34: Prefer Incomplete Types to Inaccurate Types
-
Things to Remember
naming types
,
Item 36: Name Types Using the Language of Your Problem Domain
-
Things to Remember
nominal typing
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
null values
,
Item 31: Push Null Values to the Perimeter of Your Types
-
Things to Remember
robustness principle
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
-
Things to Remember
type information in documentation
,
Item 30: Don’t Repeat Type Information in Documentation
types representing valid versus invalid states
,
Item 28: Prefer Types That Always Represent Valid States
-
Things to Remember
unions of interfaces versus interfaces of unions
,
Item 32: Prefer Unions of Interfaces to Interfaces of Unions
-
Things to Remember
type domains
,
Item 7: Think of Types as Sets of Values
-
Things to Remember
type inference
aliases
,
Item 24: Be Consistent in Your Use of Aliases
-
Things to Remember
asynchronous code
,
Item 25: Use async Functions Instead of Callbacks for Asynchronous Code
-
Things to Remember
avoiding variable reuse
,
Item 20: Use Different Variables for Different Types
-
Things to Remember
benefits of inferable types
,
Item 19: Avoid Cluttering Your Code with Inferable Types
-
Things to Remember
context in
,
Item 26: Understand How Context Is Used in Type Inference
-
Things to Remember
functional constructs and libraries
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
-
Things to Remember
object creation
,
Item 23: Create Objects All at Once
-
Things to Remember
type narrowing
,
Item 22: Understand Type Narrowing
-
Things to Remember
type widening
,
Item 21: Understand Type Widening
-
Things to Remember
type narrowing
,
Item 22: Understand Type Narrowing
-
Things to Remember
type refinements
,
Item 24: Be Consistent in Your Use of Aliases
type safety
avoid returning any types from functions
,
Item 38: Use the Narrowest Possible Scope for any Types
-
Things to Remember
ensuring
,
Things to Remember
hiding unsafe type assertions
,
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
lack of with any types
,
There’s No Type Safety with any Types
preventing regressions in
,
Item 44: Track Your Type Coverage to Prevent Regressions in Type Safety
subsets of string and
,
Item 33: Prefer More Precise Alternatives to String Types
type-safe approaches versus monkey-patching
,
Item 43: Prefer Type-Safe Approaches to Monkey Patching
type space
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
-
Things to Remember
type system
applying type annotations to function expressions
,
Item 12: Apply Types to Entire Function Expressions When Possible
-
Things to Remember
arrays, tuples, and ArrayLike
,
Item 16: Prefer Arrays, Tuples, and ArrayLike to number Index Signatures
-
Things to Remember
avoiding errors associated with mutation
,
Item 17: Use readonly to Avoid Errors Associated with Mutation
-
Things to Remember
avoiding repetition
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
-
Things to Remember
excess property checking limits
,
Item 11: Recognize the Limits of Excess Property Checking
-
Things to Remember
index signatures for dynamic data
,
Item 15: Use Index Signatures for Dynamic Data
-
Things to Remember
mapped types
,
Item 18: Use Mapped Types to Keep Values in Sync
-
Things to Remember
object wrapper types
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
as optional and gradual
,
Working with any
type declarations versus type assertions
,
Item 9: Prefer Type Declarations to Type Assertions
-
Things to Remember
type space versus value space
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
-
Things to Remember
type versus interface
,
Item 13: Know the Differences Between type and interface
-
Things to Remember
types as set values
,
Item 7: Think of Types as Sets of Values
-
Things to Remember
using editors to interrogate and explore
,
Item 6: Use Your Editor to Interrogate and Explore the Type System
-
Things to Remember
type widening
,
Item 21: Understand Type Widening
-
Things to Remember
typeof fn
,
Item 12: Apply Types to Entire Function Expressions When Possible
-
Things to Remember
typeof operator
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
,
Item 14: Use Type Operations and Generics to Avoid Repeating Yourself
TypeScript
any type drawbacks
,
Item 5: Limit Use of the any Type
-
Things to Remember
configuration settings
,
Item 2: Know Which TypeScript Options You’re Using
-
Things to Remember
experimenting with
,
Item 59: Use @ts-check and JSDoc to Experiment with TypeScript
-
Things to Remember
function statements versus function expressions
,
Item 12: Apply Types to Entire Function Expressions When Possible
installing as a devDependency
,
Item 45: Put TypeScript and @types in devDependencies
migrating to
,
Item 1: Understand the Relationship Between TypeScript and JavaScript
,
Migrating to TypeScript
-
Things to Remember
mixing with JavaScript
,
Item 60: Use allowJs to Mix TypeScript and JavaScript
relationship to JavaScript
,
Item 1: Understand the Relationship Between TypeScript and JavaScript
-
Things to Remember
,
Item 53: Prefer ECMAScript Features to TypeScript Features
release notes
,
Things to Remember
structural typing
,
Item 4: Get Comfortable with Structural Typing
-
Things to Remember
,
Item 37: Consider “Brands” for Nominal Typing
-
Things to Remember
,
Item 51: Mirror Types to Sever Dependencies
terms and set terms
,
Item 7: Think of Types as Sets of Values
type inference in
,
Item 19: Avoid Cluttering Your Code with Inferable Types
-
Things to Remember
writing for browsers
,
Item 55: Understand the DOM hierarchy
-
Things to Remember
TypeScript compiler (tsc)
code generation and type checking
,
Code with Type Errors Can Produce Output
-
Things to Remember
functions of
,
Item 3: Understand That Code Generation Is Independent of Types
TypeScript Playground
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
U
undeclared globals
,
Undeclared Globals
undefined primitive
,
Item 10: Avoid Object Wrapper Types (String, Number, Boolean, Symbol, BigInt)
-
Things to Remember
undefined value type
,
Item 15: Use Index Signatures for Dynamic Data
Underscore library
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
,
Item 33: Prefer More Precise Alternatives to String Types
,
Item 52: Be Aware of the Pitfalls of Testing Types
union types
difficulty in using
,
Item 29: Be Liberal in What You Accept and Strict in What You Produce
extending
,
Item 13: Know the Differences Between type and interface
purpose of
,
Item 20: Use Different Variables for Different Types
unions of interfaces versus interfaces of unions
,
Item 32: Prefer Unions of Interfaces to Interfaces of Unions
-
Things to Remember
unknown libraries
,
Unknown Libraries
unknown types
versus inaccurate models
,
Things to Remember
unknown versus any types
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
-
Things to Remember
unsafe casts
,
Item 40: Hide Unsafe Type Assertions in Well-Typed Functions
use strict
,
Don’t Put use strict in TypeScript
user-defined type guards
,
Item 22: Understand Type Narrowing
V
valid states
,
Item 28: Prefer Types That Always Represent Valid States
-
Things to Remember
value space
,
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
-
Things to Remember
values
assigning to variables
,
Item 9: Prefer Type Declarations to Type Assertions
-
Things to Remember
keeping in sync with mapped types
,
Item 18: Use Mapped Types to Keep Values in Sync
-
Things to Remember
null values versus non-null values
,
Item 31: Push Null Values to the Perimeter of Your Types
-
Things to Remember
types as set values
,
Item 7: Think of Types as Sets of Values
-
Things to Remember
with unknown types
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
-
Things to Remember
var
,
Use let/const Instead of var
variables
assigning values to
,
Item 9: Prefer Type Declarations to Type Assertions
-
Things to Remember
avoiding reuse for different types
,
Item 20: Use Different Variables for Different Types
-
Things to Remember
including units in variable names
,
Item 30: Don’t Repeat Type Information in Documentation
naming
,
Item 36: Name Types Using the Language of Your Problem Domain
-
Things to Remember
versions, managing for type declarations
,
Item 46: Understand the Three Versions Involved in Type Declarations
-
Things to Remember
W
webpack
,
Use ECMAScript Modules
Westbrook, Russell
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
widening
,
Item 21: Understand Type Widening
-
Things to Remember
Y
YAML
,
Item 42: Use unknown Instead of any for Values with an Unknown Type
Z
zipObject
,
Item 27: Use Functional Constructs and Libraries to Help Types Flow
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset