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
@ahejlsberg you probably already know about this one but I thought I'd confirm:
interfaceError{e}declarefunctionisError(value: any): value is Error;classCustomErrorextendsError{}functionnarrowTest(value: number|CustomError){if(isError(value)){letresult: CustomError=value;}else{letresult: number=value;// error!}}
Expected: narrowing to number in the else branch.
Actual: No narrowing: value: CustomError | number in the else branch, causing an error.
This is an effect of #10216. The issue we face here is that Error and CustomError are structurally identical from the type system's point of view, yet at runtime a CustomError is an instance of Error, but not the other way around. The implementation currently makes the assumption that when two distinct types are structurally identical, neither is an instance of the other. We could look into "cheating" and check whether one extends the other, even though technically that isn't part of the type. Maybe we just need to get over that.
@ahejlsberg you probably already know about this one but I thought I'd confirm:
Expected: narrowing to
number
in the else branch.Actual: No narrowing:
value: CustomError | number
in the else branch, causing an error.I found this in
lodash
on DefinitelyTyped.The text was updated successfully, but these errors were encountered: