#nominal Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Python NewType for Nominal IDs
Python's type system is structural — `UserId` and `PostId` are both just `int` unless you ask otherwise. `NewType` creates a distinct type with zero runtime cost for static checking only.
Rust Newtype Pattern (zero-cost wrappers)
Wrap a primitive in a tuple struct to give it a distinct type identity at the type level — without runtime cost. Replaces "is this number a UserId or a PostId?" bugs.
TypeScript Branded Types (nominal typing)
TypeScript is structurally typed, so `string` and `string` are interchangeable even when they semantically aren't (UserId vs PostId). The "brand" trick adds a phantom property that exists only at compile time, giving you nominal-ish typing.