Branded type utility — creates a nominal subtype.
Use to prevent accidental mixing of semantically different values that share the same underlying type.
Readonly
Brand discriminator — prevents accidental mixing of semantically different values that share the same underlying type.
type UserId = Brand<string, "UserId">;type OrderId = Brand<number, "OrderId">;function getUser(id: UserId) { /* ... */ }getUser("abc" as UserId); // OKgetUser(123 as unknown as UserId); // Error Copy
type UserId = Brand<string, "UserId">;type OrderId = Brand<number, "OrderId">;function getUser(id: UserId) { /* ... */ }getUser("abc" as UserId); // OKgetUser(123 as unknown as UserId); // Error
Branded type utility — creates a nominal subtype.
Use to prevent accidental mixing of semantically different values that share the same underlying type.