Professional Documents
Culture Documents
Item 8
- use a type declaration instead of a type assertion in map
const people = ['alice', 'bob', 'jan'].map(
(name): Person => ({name})
); // Type is Person[]
Item 28: Types should model only valid states, even at the cost of verboseness
Item 29: Be Liberal in What You Accept and Strict in What You Produce
Avoid “stringly typed” code. Prefer more appropriate types where not every string
is a possibility
Prefer keyof T to string for function parameters that are expected to be properties
of an object
Chapter 5:
Item 38: Use the Narrowest Possible Scope for any Types
- example: as any in a function call instead of variable declaration
- use unknown whenever the user knows more about the output of a function, and can
assign a type to the return value