-
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
Suggestion: pure abstract classes shouldn't require 'super' call #4429
Comments
This is 'by design' so we'll need a spec bug as well if we decide to change this. |
How would we detect |
Wouldn't it just look like abstract class Fred { } ...in a .d.ts file? We have to show the state and if it has a constructor, even in the .d.ts file, since that's part of the class's full shape. Wouldn't that be enough to know if you should require a constructor? |
What I mean is that these two classes have identical ambient declarations: // Requires a super call
abstract class Fred {
private p = 4;
}
// Does not require a super call
abstract class Bob {
private p;
} In theory we could say that the generated |
This is true. I guess what I'm saying is that conservatively we can know for sure in some cases, while others might be ambiguous, so we would require them even if technically it's unnecessary. I'm following more of a "pure abstract" in the C++ sense (https://en.wikibooks.org/wiki/C%2B%2B_Programming/Classes/Abstract_Classes/Pure_Abstract_Classes). Quoted: "A pure Abstract class has only abstract member functions and no data or concrete member functions." The equiv for us would be "A pure abstract class has member functions and no data or constructor" |
Though the class is marked as abstract, the class do exist at runtime. as per the ES6 spec, super needs to be invoked. if all you need is the type, either implement the class, and not extend it, or define it as an interface. |
In this example:
We currently error on the constructor in Sam saying it's an error to not have a super() call. But arguably Fred is a purely abstract, has no state, no initialization, and no constructor. There doesn't seem to be a reason to enforce the super call in this example.
The text was updated successfully, but these errors were encountered: