-
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
this subclass inference problem #15615
Comments
Using TS 2.3.2, I confirmed this error in a js file with |
We narrow out |
I see. adding |
But why does this work?
|
TypeScript doesn't catch that |
Using typescript 2.5.3 w/ noImplicitAny, strictNullChecks Here's another variation of this problem: export class Foo {x: number}
export class Bar {}
export function f(x: Foo | Bar) { x instanceof Bar || x instanceof Foo } You get an error on the Another way to think of it is the first It may be interesting to note that this is distinct from the behavior of export function g(x: string | number) { typeof x === "string" || x / 2 } This code correctly type checks because it isn't possible for Also, funny running into you here w/ the same bug I was about to report Jonathan, howdy :) |
It looks like there is a long history here: Looks like a long time ago it worked as I suggested above, but it was moved to work this way. The new feature to not allow Anyway I've left enough notes here, I'm going to go ahead and work around it by making all of the classes structurally different w/ some dummy functions. |
This seems to be resolved w/ Typescript 2.7 |
From @JonathanMEdwards on May 5, 2017 19:19
Steps to Reproduce:
Produces error:
'Property 'foo' does not exist on type 'never'.'
Copied from original issue: microsoft/vscode#26071
The text was updated successfully, but these errors were encountered: