Allow specifying interface implements clauses for the static side of classes
## Search Terms class static side syntax interface type expression ## Suggestion Currently, you can only specify the static side interface of a class with a declaration. From [the handbook](https://www.typescriptlang.org/docs/handbook/interfaces.html#difference-between-the-static-and-instance-sides-of-classes): ```ts const Clock: ClockConstructor = class Clock implements ClockInterface { constructor(h: number, m: number) {} tick() { console.log("beep beep"); } } ``` When I first wanted to do this (before looking at the docs), I tried to do it in this fashion: ```ts class Clock: ClockConstructor implements ClockInterface { ... } ``` And I was surprised to see that it didn't work. My proposal is to make this a valid syntax as it's more intuitive and understandable. I believe that forcing class expressions conflicts with TypeScript's design goals: >5. Produce a language that is composable and easy to reason about. Why use a class expression when there is no need for it? Why change your actual JavaScript logic for something that exists only in TypeScript and not in your production code. ## Use Cases Anywhere you need to set the interface of the static side of a class without having a need to specify it as an expression. ## Examples Take the example from the playground: ```ts interface ClockConstructor { new (hour: number, minute: number); } interface ClockInterface { tick(); } class Clock: ClockConstructor implements ClockInterface { construct
Posted by yandodov on Oct 9, 2019, 7:40 AM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
Allow specifying interface implements clauses for the static side of classes
## Search Terms class static side syntax interface type expression ## Suggestion Currently, you can only specify the static side interface of a class with a declaration. From [the handbook](https://www.typescriptlang.org/docs/handbook/interfaces.html#difference-between-the-static-and-instance-sides-of-classes): ```ts const Clock: ClockConstructor = class Clock implements ClockInterface { constructor(h: number, m: number) {} tick() { console.log("beep beep"); } } ``` When I first wanted to do this (before looking at the docs), I tried to do it in this fashion: ```ts class Clock: ClockConstructor implements ClockInterface { ... } ``` And I was surprised to see that it didn't work. My proposal is to make this a valid syntax as it's more intuitive and understandable. I believe that forcing class expressions conflicts with TypeScript's design goals: >5. Produce a language that is composable and easy to reason about. Why use a class expression when there is no need for it? Why change your actual JavaScript logic for something that exists only in TypeScript and not in your production code. ## Use Cases Anywhere you need to set the interface of the static side of a class without having a need to specify it as an expression. ## Examples Take the example from the playground: ```ts interface ClockConstructor { new (hour: number, minute: number); } interface ClockInterface { tick(); } class Clock: ClockConstructor implements ClockInterface { construct
Comments (0)
No comments yet. Start the discussion.