Proposal: Make base class expressions able to access class type parameters #36406
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
Base class expressions cannot reference class type parameters
Suggestion
Right now it is possible in Ts to generate base classes dynamically (via a function):
And it is also possible to reuse a generic when the base class is a "pure" class with a generic type:
However, currently it is impossible for a function that generates a dynamic class to re-use the type from the child class:
There's a (somehow ugly) workaround, which is encapsulating the generation of the child class in a function and use its result:
But it is quite ugly, and results in a new class being generated for each generic when it is not actually needed (just for the typings).
The proposal is basically to lift this constraint and allow it to be used (like it can be easily used for pure classes).
Use Cases
Right now in mobx-keystone it uses such a pattern (a function that generates a dynamic base class) to generate models:
but in order to support generics, rather than just doing this:
users have to resort to a factory pattern like this:
which is far from ideal (and this is just to get typings right).
Examples
See above
Checklist
My suggestion meets these guidelines:
It wouldn't since it is lifting a constraint that currently is just not allowed, so no current code can be using it.
The runtime behaviour would be exactly the same, it just addresses a typings problem.
The text was updated successfully, but these errors were encountered: