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
TypeScript Version: 3.2.2 (However, I believe it exists in typescript@next as well)
Search Terms:
Incorrect type narrowing in catch
type narrowing union catch
type narrowing union default
union default incorrect type
Code
functionotherWork(){thrownewError("Hi!");}functiongetNum(){return3;}functionfoo(){letx: number|null=null;try{x=getNum();otherWork();}catch(e){console.log(x&&x.toString());//Error, type of x is null, not number | null}x;}
Expected behavior:
The type of the first x in console.log(x && x.toString()) should have type number | null, the second x in x.toString() should have type number. Actual behavior:
The first x has type null, the second x has type never (as expected if the first x has type null). The type of the last x, in x; has the correct type number | null
I don't know enough about the ts compiler to know for sure, but it does appear that the PR to fix #28153 should also fix this. Should this be marked as a dup of #28153?
TypeScript Version: 3.2.2 (However, I believe it exists in typescript@next as well)
Search Terms:
Incorrect type narrowing in catch
type narrowing union catch
type narrowing union default
union default incorrect type
Code
Expected behavior:
The type of the first x in console.log(x && x.toString()) should have type number | null, the second x in x.toString() should have type number.
Actual behavior:
The first x has type null, the second x has type never (as expected if the first x has type null). The type of the last x, in x; has the correct type number | null
Playground Link:
https://typescript-play.js.org/#code/GYVwdgxgLglg9mABHKALApgJwOp0wawAoBKRAb0TUzgHdEx06BRTazQgIgAkYBCD4gG5EAXwBQoSLASIA5uigA5EAFsS5RJgUhMSAMzDxE8NHhJgcOOrJjEdxABsFiAB4AueqoBGWRAB9PBwdEAF5Ah0FbeyhMAE9yKPt7F1C5BWU1IUSk5DQsXAISSKSRRAgAQygIVERCdFIbHPsIBABnOCcAOgc4WUIUgDIB106oOABlGJgwPuIhRAB6BZY2ABpKWIAHdGRgV0QYVvD1sBRPFR9Mf3Ds8SSXSJEgA
Related Issues:
None
The text was updated successfully, but these errors were encountered: