Enums and Advanced Types
Enums
An enum gives a set of related constants readable names.
TypeScript
Discriminated unions
Combining a union type with a shared "tag" property lets TypeScript narrow which shape you're working with.
TypeScript
The ok property is the discriminant, checking it narrows result to exactly one branch of the union inside each if.