typescript
5 minTypeScript Foundations: Narrow Unknown Data Before Trusting It
Distinguish compile-time guarantees from runtime data and use narrowing, discriminated unions, and explicit parsing at service boundaries.
Loading page...
typescript
5 minDistinguish compile-time guarantees from runtime data and use narrowing, discriminated unions, and explicit parsing at service boundaries.
typescript
6 minParse unknown data and use discriminated unions to preserve operational meaning through callers.
typescript
8 minUse for-await consumption, cancellation, and iterator return semantics without hiding queues.
Q&A
Q&AThey require different caller behavior and must not collapse into null.
Validate unknown runtime data, then preserve outcome meaning in a discriminated union. Exhaustive handling exposes new states during compilation; structural validation does not establish permissions or retry safety.
typescript
5 minKeep request handlers responsive by distinguishing asynchronous waiting from CPU work, bounding concurrency, and propagating stream failures.
Q&A
Q&ANo; an adapter can hide an unbounded push queue behind a pull-shaped interface.
A consumer can request one item at a time, but callback-backed sources still need an explicit capacity and overflow policy. Tie early iterator exit and cancellation to resource cleanup.
Q&A
Q&AType assertions are erased. Treat untrusted data as unknown and validate its shape and domain constraints before relying on it.
Type assertions are erased. Treat untrusted data as unknown and validate its shape and domain constraints before relying on it.
unix
8 minUnderstand users, groups, permission bits, file descriptors, and redirection so shell and service behavior is easier to debug.