Functions, generics and narrowing
This part is about functions and the types they carry: the signature, optional, default and rest parameters, overloads, generic functions and their constraints, explicit return types, arrows and callbacks. It closes with narrowing a union through typeof, in and instanceof, and with the assertions that can lie to the compiler.
11
Function types
type a signature with parameter and return annotations, including void and never
Open
12
Parameters
optional, default and rest parameters, destructured with full type safety
Open
13
Overloads
several call shapes under one name, each with a signature, and one implementation behind them
Open
14
Generics
generic functions with a type parameter, inferred from the call or given by hand
Open
15
Constraints
limit a generic with extends, derive keys with keyof, and default a type parameter
Open
16
Return types
explicit return types against inference, and the promise an async function returns
Open
17
Arrow functions
short arrow functions, the this they keep, and inline callbacks
Open
18
Callbacks
type a callback, pass a named or an inline handler, and flatten nested async logic
Open
19
Narrowing
narrow a union with typeof, truthiness, the in operator and instanceof
Open
20
Assertions
as, the non-null operator and const assertions, and where an assertion can lie
Open