Suggestion: allow infer T in type parameter constraint of type statement
#39736
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
uhyo commentedJul 25, 2020
•
edited
Search Terms
suggestion infer extends type parameter constraint
Suggestion
Allow
infer Tin the right ofextendsof atypestatement.Examples
This suggestion allows following code:
Which behaves similarly as:
Use Cases
As demonstrated in the example, we sometimes use conditional types with the sole purpose of use of
infer T.We have to repeat some piece of code if we want to constraint what types can be passed to
ReturnType.So this suggestion provides an abbreviated syntax for this use case.
Open questions:
My opinion is yes to align with existing conditional typesanywithinfer _would change the behavior...infer T?Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: