Skip to content
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

Closed
sophiajt opened this issue Aug 24, 2015 · 6 comments
Closed

Suggestion: pure abstract classes shouldn't require 'super' call #4429

sophiajt opened this issue Aug 24, 2015 · 6 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@sophiajt
Copy link
Contributor

In this example:

abstract class Fred { }

class Sam extends Fred {
    constructor() { }
}

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.

@danquirk
Copy link
Member

This is 'by design' so we'll need a spec bug as well if we decide to change this.

@danquirk danquirk added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Aug 24, 2015
@RyanCavanaugh
Copy link
Member

How would we detect Fred's pureness if it came from an ambient declaration?

@sophiajt
Copy link
Contributor Author

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?

@RyanCavanaugh
Copy link
Member

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 Fred declaration should have an empty constructor declaration, but I don't think people would know that was significant if writing .d.ts files by hand.

@sophiajt
Copy link
Contributor Author

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"

@mhegazy
Copy link
Contributor

mhegazy commented Oct 2, 2015

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.

@mhegazy mhegazy closed this as completed Oct 2, 2015
@mhegazy mhegazy added Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels Oct 2, 2015
@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
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants