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

allow typeof expressions in extends and implements list #18271

Closed
zpdDG4gta8XKpMCd opened this issue Sep 6, 2017 · 2 comments
Closed

allow typeof expressions in extends and implements list #18271

zpdDG4gta8XKpMCd opened this issue Sep 6, 2017 · 2 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented Sep 6, 2017

const Y = { z: 7 };
class X implements typeof Y {} // <-- bummer
@aluanhaddad
Copy link
Contributor

aluanhaddad commented Sep 6, 2017

Yes please, this would be exceedingly convenient.

Perhaps this is out of scope but would it be reasonable to extend this proposal to allow for an implements clause to list any valid type expression such as T & U?

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Sep 6, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2017

In order to implement this we will have to split parsing for extends and implements into two separate paths, allow only valid expressions/expressions with type parameters in extends, and allow all types in implements.. which is doable..

but then you can write things like:

class C implements ()=>number { 
  ....
}

which looks confusing at best, and frankly ugly...

The scenarios we see here are either the T & U, and for that we believe implement T, U is more expressive and semantically better aligned with the implements clause needs.

the other is typeof x; but it is strange to allow this one and not allow others... and for that using a type alias is not that bad..

Though the current approach does not support all scenarios, we believe it is at least we are cutting off what can be specified in an implements clause in a consistent and meaningful way.

@mhegazy mhegazy added Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels Nov 7, 2017
@mhegazy mhegazy closed this as completed Nov 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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

3 participants