Branded type for compile-time type safety. Prevents mixing of different ID types at compile time.
The base type (e.g., string, number)
The brand identifier (e.g., 'MEPID', 'SessionID')
type UserID = Brand<number, 'UserID'>;type ProductID = Brand<number, 'ProductID'>;const userId: UserID = 123 as UserID;const productId: ProductID = 456 as ProductID;// This will cause a compile-time error:// userId = productId; // Error: Type 'ProductID' is not assignable to type 'UserID' Copy
type UserID = Brand<number, 'UserID'>;type ProductID = Brand<number, 'ProductID'>;const userId: UserID = 123 as UserID;const productId: ProductID = 456 as ProductID;// This will cause a compile-time error:// userId = productId; // Error: Type 'ProductID' is not assignable to type 'UserID'
Branded type for compile-time type safety. Prevents mixing of different ID types at compile time.