-
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
Intellisense/TSServer bug with self reference of class in inheritance #3170
Comments
I'm not sure if I understand correctly; is the issue you're having that without your workarounds, |
After looking more closely, I believe it is. If so, this is not a bug in the language service, this is the way the language works. Still, we understand that this can be undesirable and issue #285 tracks a solution so that you can better express the intent of your code. |
The problem with the language currently is that there is no way to say "the result of this call is an instance of the value you called it on." This makes chaining and fluent APIs difficult to write in the presence of subclassing. This limitation is pretty common in many languages, though I'd definitely like to see some improvement here as well. |
See #513 |
@DanielRosenwasser I edited the code to make it clear, the issue is that the Parent class is returned instead of Child. @CyrusNajmabadi Agree, this is a bummer. I hope the TypeScript team can fix this, because is getting annoying pretty fast. @danquirk great, I didn't found that early. Maybe this issue is related to #15 .... thanks! |
Given the following code:
The last method returns the "this" from Parent (the doOtherStuff method doesn't exists), instead of Child, so extend becomes really anoying, because I have to workarounds (both bad):
Workaround 1:
With this one, the result is the spected one, but the code is repetitive.
Workaround 2:
With this one is even worst, because I need to write every inherited function again to recover the "this" of the child.
Is this a bug or a feature?. If not a bug, then could I ask for an explanation for this and a better workaround if there is one?
Thanks!
Edit 1:
I just tested the code in Babel, and in io.js, and it works as excpected, so I think this is a TypeScript bug... Check it here
Edit 2:
I use the TypeScript compiled code, and it works as excpected, so it's a problem with tsserver/intellisense.
The text was updated successfully, but these errors were encountered: