TypeScript at scale
Core details
TypeScript is JavaScript + static types erased at emit—runtime is still JS semantics. Structural typing: shapes matter; nominal brands need tricks.
| Knob | Effect |
|---|---|
strict family | fewer any holes; more friction up front |
noUncheckedIndexedAccess | safer obj[k] |
strictNullChecks | null/undefined in type flow |
Inference: let the compiler infer locals; annotate exports and public APIs for stable contracts.
Patterns: discriminated unions for state machines; satisfies to keep literal types; avoid any—prefer unknown + narrowing.
Understanding
interface vs type: merge declaration with interface; unions/maps often need type. Teams pick one consistency rule.
Build modes: project references for monorepo compile graphs; path aliases need runtime resolution strategy (bundler).
Senior understanding
Types don’t catch all bugs: IO boundaries still need validation (zod/io-ts). Generic abuse hurts readability—balance reuse vs clarity.
Diagram
.ts source → tsc (types erased) → .js → Node / browser
│
└── types as documentation + CI gateSee also
Last updated on
Spotted something unclear or wrong on this page?