Reject fractional cent amounts
A numeric type cannot by itself guarantee whole cents. Validate integrality where money enters the typed part of the application.
Developer journal
Type design, inference and the boundary between compile-time and runtime checks.
A numeric type cannot by itself guarantee whole cents. Validate integrality where money enters the typed part of the application.
Reflection across the vertical axis changes the horizontal sign and leaves the vertical coordinate in place. Return a new point when callers retain the original.
A route registry can drive both lookup and allowed route names. Type the keys from the registry so a removed route cannot survive in a separate union.
Indexing a tuple's type by number yields a union of its element types. Literal inference determines how precise that union becomes.
A computed property name derives an object's key from a runtime value. Keep its allowed names narrow if downstream readers expect a fixed set.
References between tasks can be well typed yet point to nonexistent names. Validate membership in the actual set of task IDs as a separate step.
A touched-field map tracks interaction separately from the underlying values. A field can be touched and still contain its original value.
A typed property read can couple a key to the shape of its record. That relationship catches misspellings before they become missing runtime values.
A Float32Array stores numbers in single precision. Projecting records into it can change a decimal value even when the projected field was a number.
A public projection should explicitly copy the fields meant for its consumer. A narrower type annotation alone does not remove fields from a runtime object.
A partial input and a complete configuration serve different callers. Fill required values at one boundary so downstream code can rely on them.
A generic array wrapper can retain the type of the incoming value. That lets consumers reuse the helper without losing useful editor feedback.
An optional callback parameter is part of the callable contract. A caller may omit it, so the implementation must handle that case.
Depth-first traversal visits descendants before returning to a sibling. Declare the node shape recursively and decide how to handle empty child lists.
Pagination state needs a reliable signal for the final page. A missing cursor and an empty result are different conditions.
An initial state object establishes which variants are available before the first event. Check how literal values are inferred when assigning it.
A constructor signature describes something the helper can instantiate. The returned instance type can be inferred from the constructor argument.
Omit describes a narrower type at compile time. Removing an internal field from a payload also requires a runtime projection or destructuring step.
Extracting IDs and sorting them are separate operations. Check whether IDs need numeric comparison or lexical comparison.
A coordinate type makes a numeric operation's inputs explicit. Magnitude combines dimensions into a single scalar, so the result loses direction.
A generic Set keeps insertions consistent across the lifetime of the collection. Explicit type arguments are especially useful when the set starts empty.
A readonly literal list can be the source of truth for both runtime choices and a compile-time union. It avoids maintaining a duplicate list of allowed names.
A narrow payload type describes the exact field a function needs. Keep that contract separate from the larger database record.
Template literal types can restrict which strings are accepted as identifiers. Runtime data still needs validation when it crosses an input boundary.
An async function returns a promise even when its body returns an immediate value. Annotating that contract makes consumers await the correct shape.
Discriminant fields tie runtime branches to a finite set of names. Extracting their union keeps routing or rendering logic aligned with actual variants.
Zero is a valid score even though it is falsy. A nullish default expresses absence without erasing an actual measurement.
Readonly inputs make accidental mutation a type error. A nonmutating reverse creates a new order while preserving the caller's original sequence.
An explicit null check preserves valid values that a broad truthiness check would reject. The remaining branch gains a narrower type.
The satisfies operator checks a value against a contract without replacing its inferred type with that contract. It can catch a misspelled option early.