Thursday, February 1, 2018

Type Assertions in TypeScript

const whatever = <MySpecificType>somethingVague;

If somethingVague is an any or is somethingVague is one of many types that make up the MySpecificType type, then this allows us to be more specific in the first case and less specific in the second case. This is casting.

No comments:

Post a Comment