TypeScript best practices Apply the type-system-discipline principle skill first. | Rule | Summary | |------|---------| | Discriminated unions | Model variants with a literal discriminant so impossible states can't be represented. No optional-field bags. | | Branded types | Brand primitives with so they can't be mixed up. Validate once at the boundary. A brand comes from a verifying type guard ( ), never from . | | Constructive modeling | Build the shape so the illegal value can't be constructed. for non-empty, for even length, plus for a range. Not a runtime guard, not a wish for refinement…