runtime validation
Checking real data with JavaScript code while the program runs, so values from outside are proven correct before they are trusted.
In more detail
Types are erased, so they cannot check a network response, a file or user input. At each boundary, take the data as unknown, check its shape with type guards or a schema library, and only then give it a precise type. Everything inside the boundary can then rely on the types.
Related terms
- untrusted input — Any data a program did not create itself, including arguments, form fields, request bodies, file contents, file names and environment variables.
- unknown (type) — The type-safe type for a value that could be anything, which you must narrow before you can use it.
- type predicate — A return type written param is Type, which tells the compiler that when the function returns true, the argument has that type.
- type erasure — The removal of all TypeScript types when code is compiled, so none of them exist while the JavaScript runs.
Taught in
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- void, undefined And null: Exact Optional Property Types — Production TypeScript
- Custom Type Predicates: Functions Returning is Type — Production TypeScript
- Assertion Signatures: asserts condition And Invariants — Production TypeScript
- Exhaustive Narrowing With never In Production Handlers — Production TypeScript
- Default Generic Arguments And Multi-Type Parameters — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript