ts-tagged
Defines the Tagged<T, N>
generic type letting you created tagged types with base type T
and name N
.
Two variables of a tagged type can only be assigned to each other if they have the same base type and name.
This implements a weak form of nominal typing suitable for types shared across multiple packages.
Installation
npm install -S ts-tagged
Example
; ;; ;; sendEmailemail; // OKsendEmaildisplayName; // Compilation error: the names don't matchsendEmail"bar@example.com"; // OK: Unnamed, but the base type matchessendEmail42; // Compilation error: The base type does not match