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
letvalue=123asstring|number;// Worksif(typeofvalue==='number'){console.log(value*2);}// Does not workif((typeofvalue)==='number'){console.log(value*2);}// Does not workif(typeofvalue===('number')){console.log(value*2);}// Does not workif((typeofvalue)===('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
The text was updated successfully, but these errors were encountered:
π Search Terms
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.2#code/DYUwLgBAbghsCuIIF4IEYBMBmCMDOEeYATgJYB2A5hAD4TnwC2ARiMQNwBQnA9DxAHUA9sQDWeTqQBmEABRgAngAcQQmbARJk2iAHIGLNroCUEAN6cIEAMZDyeIaAB0wIZVkbEEAFQQMxrgBfbj4IABEhEAJyIUgAdxFRSRlZeWVVdThEU21UfSZWYhNzSxs7B2dXd08kX38gkP4IqPpYiASxZLlFFTVoLK0dWXzDIuNTCytbe0cQFzcPAZ8-AM5g3ibI6LaOpOk5NN7MzRyhkcKTCdLpirmqxc1l+rWgA
π» Code
π 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
The text was updated successfully, but these errors were encountered: