interface SubtractAction type: 'subtract'; payload: number;
type CounterAction = AddAction | SubtractAction; typescript stephen grider
Grider dances a little jig here (metaphorically). He shows you that inside a reducer, when you check action.type === 'add' , TypeScript automatically knows that action.payload is a number . Not any . Not number | undefined . A number. interface SubtractAction type: 'subtract'
Stephen Grider does not promise you will become a TypeScript contributor to the compiler. He promises you will never again push a bug where undefined is not a function at 2 AM. type CounterAction = AddAction | SubtractAction