-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
never
incorrectly inferred with type guard
#10934
Comments
This has to deal with assignability of the structural typing of TypeScript (see #202). Because For a workaround, which is buried in #202, you can see #10882 which explains how to tag your classes so they are not substitutable. |
Thanks for the explanation @kitsonk. It makes sense. However, it seems to me like this issue could still be fixed by improving type guards. The type guards should realize that I am using |
@paldepind the team has been discussing it - see for example the design meeting notes in #8503. Also there's some more background in #8168. |
Here's a similar example without
I've been able to work around this by swapping the order of the comparisons, since mine are mutually exclusive:
Another work around is to define an explicit base interface, presumably this works since then value could explicitly be neither
|
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
I was refactoring some code and suddenly some type guards in my code begin causing type errors. I've reduced my problem to the small example below. I just did
npm install -g typescript@next
to check that this also happens with the latest version.After some confusion and debugging it appears that the bug happens because the class
Empty
has no methods. If I add a random dummy method toEmpty
the code compiles again.TypeScript Version: 2.1.0-dev.20160915
Code
Expected behavior:
Code compiles without errors and
t
has the typeSinge<any>
in theelse
clause intest
.Actual behavior:
t
has the typenever
in the else clause and I get` the compile error:The text was updated successfully, but these errors were encountered: