You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a static implements keyword pairing to specify a class's static members combine to implement a particular interface. It could be the other way around:
I can directly use the implements clause to enforce the type contract on instances of a class, but the class syntax gives no direct way to enforce a type contract on the static members of the class. The best we can currently do is to declare a short-lived constant embedded in the class:
This leaves behind a little bit of run-time code, though, to enforce the type contract. In particular, this constraint appears in neither the generated .d.ts or .js files.
💻 Use Cases
This really has only one: defining the type which a class must implement for its static members.
The text was updated successfully, but these errors were encountered:
Suggestion
I would really like to get type checking of static members up front:
🔍 Search Terms
is:issue static implements label:Suggestion
Possible duplicates:
static
members #27899✅ Viability Checklist
I believe this is safe, as it would be new type-only syntax. Currently, the TypeScript compiler would treat it as a syntax error.
My suggestion meets these guidelines:
⭐ Suggestion
Add a static implements keyword pairing to specify a class's static members combine to implement a particular interface. It could be the other way around:
📃 Motivating Example
microsoft/TypeScript-Website#2636
I can directly use the
implements
clause to enforce the type contract on instances of a class, but the class syntax gives no direct way to enforce a type contract on the static members of the class. The best we can currently do is to declare a short-lived constant embedded in the class:This leaves behind a little bit of run-time code, though, to enforce the type contract. In particular, this constraint appears in neither the generated
.d.ts
or.js
files.💻 Use Cases
This really has only one: defining the type which a class must implement for its static members.
The text was updated successfully, but these errors were encountered: