-
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
Class property inference from constructor initializations in JavaScript #4955
Comments
this
property assignments
Very nice. Probably all Think
|
What is the intent of that code? Does anyone actually do that? 😕 ❓ |
Wasn't able to find any convincing cases in JS. Seen this in PHP sometimes ~ Not a huge issue but part of the question: parameter properties count as declared properties? If someone wants a pure ES6 way to declare properties, I guess |
More concrete:
Don't really want |
I assume the driving force behind this change is to let TS be able to mimic ES6-style JS classes? On one hand it seems like an unnecessary extra way to do things, but I like how it would let you copy over an ES6 class and be able to start using it with type-checking in TS. I don't think there's a good answer for parameter properties. If they're considered declared properties, it disallows their use as shorthand in conjunction with the new |
Done in JavaScript branch |
@RyanCavanaugh It sounds like this is only going to be in Salsa for now based on the design meeting notes - can you confirm that? Thanks. |
Correct |
Summary
We will support inferring the shape of
class
es from assignments to properties ofthis
in the constructor body. Example:Rules
All or none
If you declare any properties, either using an initializer or non-initialized declaration, you must declare all members this way:
Types of members
The type of each property is the union of all assignment sources:
Syntactic forms
Only assignments of the form
this.name = expr;
are recognized. Alternate syntax, e.g.this['name'] = expr
, or aliasing ofthis
(e.g.var x = this; x.foo = bar
) will not create properties.Open questions:
this.x = this.y = 0
) might be commonOther issues mentioning this: #766, #2393, #2606.
The text was updated successfully, but these errors were encountered: