Closed
Description
TypeScript Version: 3.9.2
Search Terms:
instanceof narrow derived
Code
class CustomError extends Error { extra: string = 'hello' }
const error: Error = new CustomError()
if ('extra' in error) {
// code path reached at runtime
error // type: never
} else {
// code path not reached at runtime
error // type: Error
}
Expected behavior:
error
inside the if
block is still of type Error
Actual behavior:
error
inside the if
block is of type never
Related Issues:
None that seemed to match.