Repository navigation
Commit 804869d
committed
Infer the constraint of an infer type parameter without instantiating
The constraint of U in a type reference such as S<infer U> is inferred
from the constraint of the corresponding type parameter of S. Finding
that type parameter resolved the type of the reference, instantiating
S with U, which can itself need the constraint of U. In
type Copy<T> = { [K in keyof T]: T[K] };
type S<T extends object> = Copy<{ x: 0 } & T>;
type I = {} extends S<infer U> ? U : never;
U had no constraint, and did not satisfy object, when the type
arguments of S<infer U> were checked first, but had the constraint
object when I was queried first. The type parameters of the declaration
the reference refers to are now used directly.
Fixes 384601 parent 2829c07 commit 804869d
2 files changed
Lines changed: 27 additions & 17 deletions
File tree
- tsc
- internal/checker
- testdata/baselines/reference/compiler
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17997 | 17997 | | |
17998 | 17998 | | |
17999 | 17999 | | |
18000 | | - | |
| 18000 | + | |
18001 | 18001 | | |
18002 | 18002 | | |
18003 | 18003 | | |
| |||
18064 | 18064 | | |
18065 | 18065 | | |
18066 | 18066 | | |
| 18067 | + | |
| 18068 | + | |
| 18069 | + | |
| 18070 | + | |
| 18071 | + | |
| 18072 | + | |
| 18073 | + | |
| 18074 | + | |
| 18075 | + | |
| 18076 | + | |
| 18077 | + | |
| 18078 | + | |
| 18079 | + | |
| 18080 | + | |
| 18081 | + | |
| 18082 | + | |
| 18083 | + | |
| 18084 | + | |
| 18085 | + | |
| 18086 | + | |
| 18087 | + | |
| 18088 | + | |
| 18089 | + | |
| 18090 | + | |
| 18091 | + | |
| 18092 | + | |
18067 | 18093 | | |
18068 | 18094 | | |
18069 | 18095 | | |
| |||
0 commit comments