-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type guard with instanceof fails to narrow type in else
block
#1719
Comments
This is by design. The expression f1({ bar = "hello" }); and it would be a perfectly fine instance of the Bar type. User-defined type guard functions (#1007) would be trusted to deliver a conclusive result, but they're not implemented yet. |
Structurally yes, but in practice we don't expect them to be compatible at all: var bar = { bar : 'bar' };
if(bar instanceof Bar){
// Not going to happen
} I would vote to have the I'm still not sure about user-defined type guard functions. The proposed syntax looks foreign and I'm not very happy with introducing code just to coax the type system into doing things. |
Gonna leave this as a suggestion for the moment and see how type guards play out for a bit to find the right balance of soundness vs practicality. |
Tagging this as something that needs discussion. Based on available evidence, no one writes an |
Approved. We should remove union type constituents that are assignable to the return type of the instanceof operand's construct signatures. |
I will try to tackle this issue. |
We need a plurp for this in https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md |
thanks @tinganho! |
Hi,
TS Version: 1.4
In the following:
is there any reason why in the
else
block we are failing to narrow the type toFoo
?The text was updated successfully, but these errors were encountered: