- Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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
function isError(error: Error | any): error is Error { return error instanceof Error; } try { throw new Error('test'); } catch(hookError) { if(isError(hookError)) { const errorHandler = class extends Error { log() { // hookError is any console.log(hookError.message); } }; } else { throw hookError; } }
Expected behavior: hookError in console.log should have type Error
Actual behavior: hookError has type any
Related Issues: I think this #30557 could be same issue, but not sure
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug