Lesson 8 / 28
Function Types
Describe function shapes with type aliases so callbacks are checked, and know when to use void.
A type for functions
A function type looks like an arrow function signature: params in, type out.
type MathOp = (a: number, b: number) => number;
const add: MathOp = (a, b) => a + b;
const multiply: MathOp = (a, b) => a * b;Typing callbacks
Function-type parameters let TS check the callback you pass in — the wrong shape is flagged immediately.
void vs undefined
void means "the return value should be ignored"; undefined means "the value is literally undefined". Use void for callback return types.