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

Abstract class expressions #4578

Closed
weswigham opened this issue Sep 1, 2015 · 7 comments
Closed

Abstract class expressions #4578

weswigham opened this issue Sep 1, 2015 · 7 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@weswigham
Copy link
Member

Aren't a thing?

let cls = abstract class {
    abstract doThing();
    myFoo(): number { return 42; }
}

Just curious if they're supposed to be, since class expressions and abstract were both added in 1.6.

@danquirk
Copy link
Member

danquirk commented Sep 2, 2015

I'm not sure whether this omission was intentional. We could presumably allow it if there's some compelling reason to, seems unlikely to be something that would be used much though.

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Sep 2, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Sep 2, 2015

That was intentional. We should reconsider thought.

@mhegazy mhegazy added the In Discussion Not yet reached consensus label Sep 2, 2015
@weswigham
Copy link
Member Author

I feel like not having them breaks the class/class expression duality a bit. Plus, it makes it so I can't blanket rewrite all classes into class expressions.

As far as non-style related usefulness goes... having abstract class expressions lets you get more typesafety in abstract class factory patterns, I guess? (Wow that sounds java-y)

It also has utility for mixin factories which require functionality on the thing they're mixed into to function.

I think the biggest reason is simply class/class expression symmetry though.

@mhegazy mhegazy added the Declined The issue was declined as something which matches the TypeScript vision label Oct 2, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Oct 2, 2015

We would like to keep the syntax as simple as possible; Could not find any blocked scenarios by now allowing abstract on class expressions. So, use an abstract class declaration instead.

@mattpap
Copy link

mattpap commented Jul 27, 2017

@mhegazy, I would like this to be reconsidered. Perhaps prior to addition of mixins to TypeScript, there wasn't much reason for having this feature, but now, at least I have cases where it would be convenient to have a mixin produce an abstract class and that requires abstract class expressions. Currently I can walk around this issue, but I would prefer not to. I don't know TypeScript compiler's internals much, but I would expect all necessary tooling to be available to allow this feature. If the only reason not to allow this is simplicity, then this approach may seem simple only because there is no documentation (I'm aware of) saying this is intentionally not supported and there are no useful error messages from the parser (#17416).

@aluanhaddad
Copy link
Contributor

You don't need to use a class expression to create a mixin though. You can create a local class inside the function and then return it. That class may be abstract.

@mattpap
Copy link

mattpap commented Jul 29, 2017

You can create a local class inside the function and then return it.

Unfortunately this doesn't work with --declaration and fails with TS4060.

@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

5 participants