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
If I use variable which has type set via type guard in nested anonymous class - it becomes of type any. TypeScript Version: 3.8.3
Search Terms: Type guard, type propagation
Code
functionisError(error: Error|any): error is Error{returnerrorinstanceofError;}try{thrownewError('test');}catch(hookError){if(isError(hookError)){consterrorHandler=classextendsError{log(){// hookError is anyconsole.log(hookError.message);}};}else{throwhookError;}}
Expected behavior: hookError in console.log should have type Error
Activity
MartinJohns commentedon Mar 11, 2020
Most likely the same issue as #9998.
RyanCavanaugh commentedon Mar 11, 2020
In addition to #9998,
hookErrorhas typeany, andanys don't get narrowed by type guards. See other issues on annotatedcatchclause variables.typescript-bot commentedon Mar 14, 2020
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.