Get the latest tech news
TypeScript: Branded Types
How to brand TypeScript types for norminal typing
Much like in the TypeScript mapped types article, the key lies in creating a field with the name of a symbol to act as our id. TypeScript won't let us pass an instance of B to the function accepting A because it's missing the brand field - brilliant! For completeness, here's the same kind of thing to remove the brand and go back to plain ol' TypeScript types:
Or read this on Hacker News