|
|
|
|
|
by simulate-me
1544 days ago
|
|
Another very common case in TypeScript (and other languages) is union types. Other languages have constructs for checking the underlying type of a union type directly, but typescript is smart enough to figure it out based off of the properties of the constituent types and what you've checked so far in your code. e.g. interface A { type: 'a' }
interface B { type: 'b' }
type C = A | B;
const c: C = ...;
if (c.type === 'a') { /* c is of type A here */ }
|
|
I guess the exception would be if you have a non-homogenous array that you try to map over. In that case there's probably no way around boxing the values.