4 ms·
If your something function was `something (num: string|number)`, typescript can safely trust that`num` is a number in the block proceeded by your call to assert
by mceachen 7y ago
If your something function was `something (num: string|number)`, typescript can safely trust that`num` is a number in the block proceeded by your call to assert because it knows it must be a number, not a string.
- jiofih 7y agoThis, and undefined values. Will be of huge value for dealing with protobuf data, where all keys are optional.
- deepersprout 7y agoIf the `something` function had `(num: string | number)` I would not be able to call `assertIsInRange(num: number)` because `Argument of type 'string | number' is not assignable to parameter of type 'number'.` So If I wanted to do that I would have to if (typeof num === 'number') { assertIsInRange(num); } anyway. I think I still don't get it.