-
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
Question: Why does "this" not have a type in function assigned to class prototype #8024
Comments
Additionally, the resolution of the Type for
results in |
Not sure why the type of Code fragment to use:
|
OK. I understand that |
I do not think there is really a good reason why it is the way it is. It is definitely possible to flow the |
In the meantime, the workaround is to give class Configuration {
// ...
public useLocalStorage(this: this): void {
}
} Then contextual typing will pick up the type of |
@sandersn Thank-you. My context here is walking the AST to find identifiers to minify. In this particular case a user had an issue with his code ( this gist of it is above ) not being minified properly. As @mhegazy said, there is no reason why the type of |
PRs are welcomed. |
Was any progress made on this? |
In 2.3 with Configuration.prototype.useLocalStorage = function() {
this.storage = "NodeFileStorageProvider"
}; Should give the type You can also use the new |
Fixed by #14141 |
TypeScript Version:
1.8.9
Code
Expected behavior:
When walking the AST I use:
to obtain the identifier and its possible associated symbol when the node is SyntaxKind.Identifier.
for the first 2 references to the private property
storage
, I obtain the identifier and the symbol (which correctly have the sameId
). With the prototype function assigned to useLocalStorage the reference tostorage
the call tothis.checker.getSymbolAtLocation( identifier )
does not return a symbol.Actual behavior:
I am using the AST to identify identifiers which may be minified/shortened. The 1st and 2nd reference to
storage
gets shortened as it is a private property.My expectation was that the reference to
storage
would have the same symbol ( not undefined ) as the other references to thestorage
property.The text was updated successfully, but these errors were encountered: