-
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
Opting out for super call requirement? #9503
Comments
In plain JavaScript: class EVE extends HTMLElement {
constructor() {
super(); // TypeError: Illegal Constructor
return document.createElement("sn-eve");
}
}
let eve1 = new EVE();
let eve2 = document.createElement("sn-eve"); So not only is it "unwanted", if |
What's the point of making |
@MattiasBuelens I can: class EVE extends HTMLElement {
constructor() {
if ({} === undefined) {
super();
}
const tempThis = document.createElement("sn-eve");
Object.setPrototypeOf(tempThis, EVE.prototype);
return tempThis;
}
eve() {
return 3;
}
}
console.log(new EVE().eve()) // 3
console.log(new EVE() instanceof EVE) // true |
@saschanaz Okay, I guess that works. What about a subclass of class DerivedEVE extends EVE {
constructor() {
super();
this.foo = "bar";
}
} I mean sure, you can probably find some roundabout way to make I just don't see the value of being able to not call |
I have to admit that it's not simple but it still is ES6, and if TypeScript still wants to require |
I think that this a duplicate of #7285, so I'll redirect the convo to there. |
TypeScript Version: master branch
Code
Expected behavior:
It should work if a constructor function return an object which is structurally compatible with the declared class.
Actual behavior:
Error: Constructors for derived classes must contain a 'super' call.
Workaround:
The text was updated successfully, but these errors were encountered: