-
Notifications
You must be signed in to change notification settings - Fork 12.8k
instanceof type guard fails with a static toString
method
#27276
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
Comments
What is the code in |
This comment was marked as outdated.
This comment was marked as outdated.
That reduced example is working when I try it. |
@Andy-MS Ok so I think I found part of the problem. It weirdly involves a static |
toString
method
Hey, any movement on this? I just hit the same issue and it took me quite a while to figure out. I had an separate I couldn't get the OP playground link to work for me, but you can paste this in to see what I mean:
Note that it's not only an issue when the superclass has a static |
I'm looking at old bugs for ones that appear to be fixed; all of the snippets in this issue appear to have been fixed from at least 3.3 and up (maybe even older). |
TypeScript Version: 3.0.3
Options:
--strict --noImplicitAny --noImplicitThis --noImplicitReturns --target="ES2017" --module="CommonJS"
Search Terms: instanceof type guard class "toString"
Code:
Expected behavior:
The type of
smart_thing
should be narrowed toRobot
.Actual behavior:
The type of
smart_thing
has not been narrowed fromPerson | Robot
.When the static method
Thing.toString
is renamed or removed, or its parameter is deleted, the problem goes away.Playground Link:
TypeScript Playground
The text was updated successfully, but these errors were encountered: