Declare generics in type assertion / generic constraint and reuse #41033
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
generic, type assertion, narrowing, constraint, reuse
Suggestion
Today there is no way to do that.
The following does not work:
The current workaround is to redeclare or compose the base function:
This unnecessary increase the size of the code.
Use Cases
There are cases where the functionality of a function only differs in their types.
To provide the best experience in TypeScript,
I would like to create some of the common variations of these function but using the same underlying function to keep the actual code size small.
Here is a simple example in
type-plus
:This proposal allows better reuse of generic types and provide better composability.
It also narrow the gap between the ability to type functions vs variables.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: