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
// This function correctly narrows the type of tag// and gives us the correct return typefunctionvalidFunction(tag: number|undefined): number|false{return!!tag&&tag}// This function allegedly returns `number | false | undefined`,// and gives a TS error, even though that is obviously not true.functioninvalidFunction(tag: number|undefined): number|false{returnBoolean(tag)&&tag}
Expected behavior:
I expect using a Boolean() BooleanConstructor to narrow the type as effectively as the !! operator.
Actual behavior:
The Boolean constructor does not narrow the type correctly. I found this when attempting to refactor some code to follow the `no-implicit-coercion ESLint rule.
TypeScript Version: 3.8.3 + Nightly
Search Terms:
Inference
Boolean
Code
Expected behavior:
I expect using a
Boolean()
BooleanConstructor to narrow the type as effectively as the!!
operator.Actual behavior:
The Boolean constructor does not narrow the type correctly. I found this when attempting to refactor some code to follow the `no-implicit-coercion ESLint rule.
Playground Link:
https://www.typescriptlang.org/play/?ts=4.0.0-dev.20200506&ssl=3&ssc=2&pln=1&pc=1#code/GYVwdgxgLglg9mABDMA3AhgGxgEwGLjTxgAUU6A5gFyJggC2ARgKYBOiAPouDs8CsxwBKGnSZtOiYFgDOzRAG8AsAChEiVsyghWSAEJw4mZulLkKQxADIric6oC+q1aEiwEiDNnyF3ZyqIMLOxcPHwCwoHiIVKy8spqGlo6SACEqebWtvYqDkA
Related Issues:
Misc: If this does turn out to be a bug, I'm happy to write a PR to fix this given some guidance.
The text was updated successfully, but these errors were encountered: