-
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
Return type of 'super()' should be 'this', not 'void' #42298
Comments
Why should/must it be 'this'? I am not questioning that it could be this, as a matter of design choice. Does the current return type |
Because that's the behavior of class Base {}
class Derived extends Base {
constructor() {
let x = super();
console.log(x === this);
}
}
new Derived(); // logs: true |
Maybe related? #38519 |
Duplicate of #37847. |
So the reason 'for it' would be so that JS code could pass the TS compiler. I can see reasons 'against it': |
That’s already supported: let x: this; |
class MyArray extends Array {
constructor () { return super(); }
} It's faster than default |
For class MyArray extends Array {
constructor(length = 0) { return super(+length) }
} to correctly support |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Found when reviewing #29374. We currently treat the return type of
super()
asvoid
, but it really should bethis
.TypeScript/tests/baselines/reference/derivedClassSuperProperties.errors.txt
Lines 534 to 536 in eb7388a
Originally posted by @rbuckton in #29374 (comment)
The text was updated successfully, but these errors were encountered: