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…
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