Closed as not planned
Description
π Search Terms
- type narrowing
- typeof expression
π Version & Regression Information
- This changed between versions 3.3 and 5.7
- This changed in commit or PR: unclear
β― Playground Link
π» Code
let value = 123 as string | number;
// Works
if (typeof value === 'number') {
console.log(value * 2);
}
// Does not work
if ((typeof value) === 'number') {
console.log(value * 2);
}
// Does not work
if (typeof value === ('number')) {
console.log(value * 2);
}
// Does not work
if ((typeof value) === ('number')) {
console.log(value * 2);
}
π Actual behavior
As soon as parentheses are added around the typeof
expression or the value it's being compared against, narrowing no longer works.
π Expected behavior
Narrowing shouldn't be affected by parentheses.
Additional information about the issue
No response