Carry over source constraints to the inferred type parameter #51108
Labels
Experimentation Needed
Someone needs to try this out to see what happens
Suggestion
An idea for TypeScript
Milestone
Suggestion
π Search Terms
infer, constraints, generic, extends
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
It would be nice if the
infer T
wouldn't lose the source constraint. I've always wondered why this is lost and couldn't find any explanation behind this in the issues etc. @DanielRosenwasser has suggested here that it might be worth opening an issue about this.Note that since 4.7 it is possible to add extends Constraints on infer Type Variables - the feature request here is different because the constraint is known upfront. Such
extends
would still be useful with the proposed feature because it can be used to limit the number of conditional types both when the source constraint is completely unbound/unknown or when you simply want to match a subtype of the source constraint.π Motivating Example
I've bumped into this on several occasions, even such a simple doesn't compile right now:
π» Use Cases
It would allow us to skip a lot of error-prone repetition when working with the infer keyword.
The text was updated successfully, but these errors were encountered: