-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Infer declarations are allowed in generic constraints, but do not infer generic constraint types #41040
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
In version 4.2.0-dev.20201115, Things I tried: type ConstraintOf<Fn extends <S>(arg: S) => any> = Fn extends <S extends infer Constraint>(arg: S) => any
? Constraint
: never; type ConstraintOf<Fn extends <S extends unknown>(arg: S) => any> = Fn extends <S extends infer Constraint>(arg: S) => any
? Constraint
: never; type ConstraintOf<Fn extends <S extends Constraint, Constraint>(arg: S) => any> = Fn extends <S extends infer Constraint>(arg: S) => any
? Constraint
: never; In every case, |
Well, I found a workaround. type ConstraintOf<Fn extends <S extends any>(arg: S) => any> = Fn extends (arg: infer Arg) => any ? Arg : never; Now The bug should stay open, though, because as far as I can tell, the other variations on this idea should have worked, too, and it’s kind of madness that this one worked and those didn’t. If anything, this version makes way less sense. What’s occurring here is that trying to test |
This cost me some hours today, +1 |
TypeScript Version: 4.0.2
Search Terms: generic constraint, extends infer
Code
Expected behavior:
InferredConstraint
isnumber
.infer
declaration is disallowed within a generic constraint clause.Actual behavior:
InferredConstraint
isnever
Playground Link: https://tsplay.dev/gWoYlN
Related Issues: #1213
The text was updated successfully, but these errors were encountered: