-
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
Function declaration with aliased this
not treated as a constructor
#39842
Comments
cc: @DanielRosenwasser, with whom I discussed this earlier |
this
not treated as typethis
not treated as a constructor
this
not treated as a constructorthis
not treated as a constructor
The object isn't relevant in this case - you just need the function declaration and the aliased function Foo(url) {
var scope = this;
scope.callbackFn = function () {
//...
}
}
var foo = new Foo();
// ^? |
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the 2 repros in this issue running against the nightly TypeScript. If something changes, I will post a new comment. Issue body code block by @uniqueiniquity
Historical InformationIssue body code block by @uniqueiniquity
Comment by @uniqueiniquity
|
Currently constructor functions are identified in the binder using syntactic markers like this-property assignment: |
Makes sense. |
Just based on our user tests, I believe it's pretty common. It is quite an old pattern by now, so I'm not sure how many editor-hours it still takes up. That is, the code written like this may never be opened in an editor anymore. Existing jsdoc we have that could be added:
function Foo() {
/** @type {Function} */
this.callbackFn
}
new Foo().callbackFn However, there aren't likely to be any of those -- I've only ever seen |
@uniqueiniquity and I prototyped a hacky solution in the binder, which looks like it would work pretty well. Basically, when binding a variable declaration that looks like The prototype immediately pointed out some places to fix:
|
TypeScript Version: 3.9.7
Search Terms:
this, alias
Code
Expected behavior:
service: dataService
and should offerupdateData
anddisable
in completion.Actual behavior:
service: any
Playground Link: Workbench Repro
Related Issues:
#36618
The text was updated successfully, but these errors were encountered: