Skip to content

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

Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Aug 3, 2016

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.

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.
@sandersn
Copy link
Member Author

sandersn commented Aug 3, 2016

@RyanCavanaugh @weswigham mind taking a look?

@@ -7,4 +7,19 @@ function C() {
}
C.prototype.m = function() {
this.nothing();
};
}

Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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
Copy link
Contributor

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.)

Copy link
Member Author

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.

@sandersn
Copy link
Member Author

sandersn commented Aug 8, 2016

@weswigham I just got a test timeout failure on one of the linux workers with workerCount=4. 😿

@weswigham
Copy link
Member

weswigham commented Aug 8, 2016 via email

@yuit
Copy link
Contributor

yuit commented Aug 8, 2016

I like the new name 😸

@mhegazy
Copy link
Contributor

mhegazy commented Aug 16, 2016

👍

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.
@sandersn sandersn merged commit 9769718 into master Aug 17, 2016
@sandersn sandersn deleted the allow-js-multiple-declaration-of-constructor-properties branch August 17, 2016 17:58
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants