DEV Community

Discussion on: TypeScript Union type a deeper look

Collapse
 
peerreynders profile image
peerreynders

Nitpick - TypeScript Deep Dive: Type Assertion vs. Casting:

The reason why it's not called "type casting" is that casting generally implies some sort of runtime support. However, type assertions are purely a compile time construct and a way for you to provide hints to the compiler on how you want your code to be analyzed.

.

Here we cast an array of possible values as the type of the Status type.

typeof STATUS[number] establishes a type context that refers to the union of all the literal types from the values found in the STATUS array.

It's important to note that you must cast the variable as a const.

It's a const assertion similar to a type assertion.


No Discriminated Unions (alt)?