-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allow JS multiple declarations of ctor properties #10123
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
Allow JS multiple declarations of ctor properties #10123
Conversation
When a property is declared in the constructor and on the prototype of an ES6 class, the property's symbol is discarded in favour of the method's symbol. That because the usual use for this pattern is to bind an instance function: `this.m = this.m.bind(this)`. In this case the type you want really is the method's type.
@RyanCavanaugh @weswigham mind taking a look? |
@@ -7,4 +7,19 @@ function C() { | |||
} | |||
C.prototype.m = function() { | |||
this.nothing(); | |||
}; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a test that does this in the opposite order (with the constructor below the method declarations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
The extra `else` caused a ton of test failures!
@@ -2137,6 +2137,7 @@ namespace ts { | |||
/* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol | |||
/* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums | |||
/* @internal */ isReferenced?: boolean; // True if the symbol is referenced elsewhere | |||
/* @internal */ isDiscardable?: boolean; // True if a Javascript class property can be overwritten by a method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could you name the property ? (e.g isMethodOverwritable
etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. I ended up with isReplaceableByMethod
but tell if you want me to change it.
@weswigham I just got a test timeout failure on one of the linux workers with |
Grrr.... Being unable to predict starvation is a pain. For now, rerun the
build and I'll reduce worker count to 3.
|
I like the new name 😸 |
👍 |
Also simply it considerably after noticing that it's *only* called for Javascript files, so there was a lot of dead code for TS cases that never happened.
Fixes #9880
When a property is declared in the constructor and on the prototype of an ES6 class, the property's symbol is discarded in favour of the method's symbol. That because the usual use for this pattern is to bind an instance function:
this.m = this.m.bind(this)
. In this case the type you want really is the method's type.