Ability to parametrize generic function type #44521
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
Suggestion
I would like to propose something along the lines of $Call utility type in Flow so it is possible to represents the result of calling a generic function with a concrete parameters.
Alternatively could be an utility type that hoists parameters from generic function type into type itself e.g.
Or yet another alternative might be to add some way to parametrize through
infer
e.g. I would have expected following to work:🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
📃 Motivating Example
Today it seems impossible capture return type of the generic function, even when concrete type of the input is known. Both built-in
ReturnType
andinfer
based solutions turn generics into a unknowns.Here is concrete example:
As per #33185 (comment) it is possible to accomplish this at the implementation level, however I do not believe it is possible to do it at the type level.
💻 Use Cases
Libraries that generate more complex interfaces from a simple ones, something like RPC client for a service with generics becomes impossible here to express:
The text was updated successfully, but these errors were encountered: