Contextually type this in object literals in JS#17252
Conversation
Previously, `this` would only get a contextual type inside object literals with `--noImplicitThis` turned on in Typescript files.
|
This is likely too restrictive - I've previously argued that what you really want is the contextual type |
|
Isn't const o = {
p: 12,
m() {
return this.p + this.x
}
}And |
| method() { | ||
| this; | ||
| this.prop; | ||
| this.method; |
There was a problem hiding this comment.
Add a test for unknown property. Should be no error, get any.
weswigham
left a comment
There was a problem hiding this comment.
I'm a sucker for changes that are only one line before tests. Nice one!
|
From conversation with @Andy-MS, note that if you make a call like this: transformsPropertiesIntoMethods({
p: 12,
m() {
return this.p()
}
})Then you will get an error with |
Previously,
thiswould only get a contextual type inside object literals with--noImplicitThisturned on in Typescript files.Fixes #16184