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
Let's imagine that we want to abstract object serialization, it would be natural to require it to have both a serialize method, and a deserialize static method.
Originally we would have only been able to define serialize as it was impossible to type the static members of a class. Until now!
What do you want to use this for?
Enforce generalized class static members to be properly normalized.
What shortcomings exist with current approaches?
You cannot type static members cleanly.
What workarounds are you using in the meantime?
I have a utility function that does nothing for the sole purpose of generating errors in TS in the file where the class is declared rather than where the constructor is used.
But it pollute the resulting JS code with pointless code at runtime.
// @ts-expect-error: unused parameter because it's not supposed to do anything at runtime.exportfunctionstaticImplements<T>(constructor: T): void{}
π Search Terms
class static members type
class static type
class static interface
class static implements
class static members constraint
β Viability Checklist
β Suggestion
Add the ability to type classes static members using the
satisfies
keyword.Reuse
satisfies
because it must not alter the effective type of the class, only constrained it.π Motivating Example
TypeScript let you type constrained instanciated objects.
Let's imagine that we want to abstract object serialization, it would be natural to require it to have both a
serialize
method, and adeserialize
static method.Originally we would have only been able to define
serialize
as it was impossible to type the static members of a class. Until now!π» Use Cases
What do you want to use this for?
Enforce generalized class static members to be properly normalized.
What shortcomings exist with current approaches?
You cannot type static members cleanly.
What workarounds are you using in the meantime?
I have a utility function that does nothing for the sole purpose of generating errors in TS in the file where the class is declared rather than where the constructor is used.
But it pollute the resulting JS code with pointless code at runtime.
Example of use:
The text was updated successfully, but these errors were encountered: