Defining Union Types From Immutable Data

All the above examples are great ways to utilize the const assertion in your code, but I think I’ve found another really nifty use for them: defining union types from immutable data. This can be used in order to make the usages of such data more type-safe, without the additional maintenance overhead!
Let me explain through a worked example…

Defining a Type-Safe Interface

Say I am developing an API that uses a well-defined set of cars, such that they only represent several manufacturers.

#web dev #typescript #fun #profit

For Fun and Profit, Use TypeScript const Assertions
1.20 GEEK