Compatibility

Suppose you want the following program to produce an error if an argument is passed with incorrect units.

One way to make these types incompatible is to add a "brand member" which stores a sentinel value.

This means the brand can now be detected at runtime (by reading the _brandA property) as well as at compilation type by TypeScript.

Was this page helpful?