You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// GOOD EXAMPLEfunctionf1(x: any): asserts x is number|undefined{}letv1: number|string|undefined;f1(v1)typet1=typeofv1;// t1 = number | undefined, as excepted// BUGGY EXAMPLEfunctionf2(x: any): asserts x is 6|undefined{}letv2: number|string|undefined;f2(v2)typet2=typeofv2;// t2 = undefined. Expected to be 6 | undefined
Related Issues: I went through the comments of the popular #32695 by @ahejlsberg and also searched in the existing issues but couldn't find any similar problem being reported in the past.
FWIW, I ran into this trying to write a assertIsInEnumValues for Numeric Enums. (related StackOverflow question: https://stackoverflow.com/a/61058457)
The text was updated successfully, but these errors were encountered:
@jack-williams thanks for commenting. It's definitely not limited to undefined (I just tested and it has the same bug with boolean as well). However, I can definitely smell that "branded primitives" discussed at #31206 might have caused it.
TypeScript Version: 3.9.0-dev.20200406
Search Terms: assertion, function, narrowing, numeric types
Code
Expected behavior:
t2
must be6 | undefined
.Actual behavior:
t2
isundefined
only.Playground Link: Playground Link
Related Issues: I went through the comments of the popular #32695 by @ahejlsberg and also searched in the existing issues but couldn't find any similar problem being reported in the past.
FWIW, I ran into this trying to write a
assertIsInEnumValues
for Numeric Enums. (related StackOverflow question: https://stackoverflow.com/a/61058457)The text was updated successfully, but these errors were encountered: