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

Class expressions don't support constructors that return any #5914

Closed
spion opened this issue Dec 3, 2015 · 2 comments
Closed

Class expressions don't support constructors that return any #5914

spion opened this issue Dec 3, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@spion
Copy link

spion commented Dec 3, 2015

Example:

function f(T:{new (...args:any[]):any}) {
    return class extends T {}
}

Error:

src/test.ts(2,23): error TS2509: Base constructor return type 'any' is not a class or interface type.

Seemingly arbitrary fix:

interface I {}
function f(T:{new (...args:any[]):I}) {
    return class extends T {}
}

Afaik any should be an acceptable type here?

@mhegazy
Copy link
Contributor

mhegazy commented Dec 3, 2015

Extend clause only supports object types, no type arguments, no intersection, no union, and since any can be any of these, it is not supported. a target of an extend clause must be something that has a "known shape", so that the extend checks can run when checking the class body, and give meaningful errors about what a class did or did not extend incorrectly.

i think this issue is a duplicate of #4890

@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 3, 2015
@mhegazy mhegazy closed this as completed Dec 3, 2015
@spion
Copy link
Author

spion commented Dec 4, 2015

There is a meaningful way to check whether it extends {}. That doesn't work either though:

function f(T:{new (...args:any[]):{}}) {
    return class extends T {}
}

Yields the same error.

If however you use a named interface, it doesn't. I can maybe accept any not unifying with something (not really, it doesn't make sense, but lets say it does as there is no structure to check), but rejecting an interface just because its anonymous, not defined as an interface { ... } - that part seems way too arbitrary to me.

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants