|
| 1 | +=== tests/cases/compiler/inferTypeParameterConstraints.ts === |
| 2 | +// Repro from #42636 |
| 3 | + |
| 4 | +type SubGuard<A, X extends [A]> = X; |
| 5 | +>SubGuard : Symbol(SubGuard, Decl(inferTypeParameterConstraints.ts, 0, 0)) |
| 6 | +>A : Symbol(A, Decl(inferTypeParameterConstraints.ts, 2, 14)) |
| 7 | +>X : Symbol(X, Decl(inferTypeParameterConstraints.ts, 2, 16)) |
| 8 | +>A : Symbol(A, Decl(inferTypeParameterConstraints.ts, 2, 14)) |
| 9 | +>X : Symbol(X, Decl(inferTypeParameterConstraints.ts, 2, 16)) |
| 10 | + |
| 11 | +type IsSub<M extends any[], S extends any[]> = M extends [...SubGuard<M[number], infer B>, ...S, ...any[]] ? B : never; |
| 12 | +>IsSub : Symbol(IsSub, Decl(inferTypeParameterConstraints.ts, 2, 36)) |
| 13 | +>M : Symbol(M, Decl(inferTypeParameterConstraints.ts, 4, 11)) |
| 14 | +>S : Symbol(S, Decl(inferTypeParameterConstraints.ts, 4, 27)) |
| 15 | +>M : Symbol(M, Decl(inferTypeParameterConstraints.ts, 4, 11)) |
| 16 | +>SubGuard : Symbol(SubGuard, Decl(inferTypeParameterConstraints.ts, 0, 0)) |
| 17 | +>M : Symbol(M, Decl(inferTypeParameterConstraints.ts, 4, 11)) |
| 18 | +>B : Symbol(B, Decl(inferTypeParameterConstraints.ts, 4, 86)) |
| 19 | +>S : Symbol(S, Decl(inferTypeParameterConstraints.ts, 4, 27)) |
| 20 | +>B : Symbol(B, Decl(inferTypeParameterConstraints.ts, 4, 86)) |
| 21 | + |
| 22 | +type E0 = IsSub<[1, 2, 3, 4], [2, 3, 4]>; // [1 | 2 | 3 | 4] |
| 23 | +>E0 : Symbol(E0, Decl(inferTypeParameterConstraints.ts, 4, 119)) |
| 24 | +>IsSub : Symbol(IsSub, Decl(inferTypeParameterConstraints.ts, 2, 36)) |
| 25 | + |
| 26 | +type E1 = [1, 2, 3, 4] extends [...infer B, 2, 3, 4, ...any[]] ? B : never; // unknown[] |
| 27 | +>E1 : Symbol(E1, Decl(inferTypeParameterConstraints.ts, 6, 41)) |
| 28 | +>B : Symbol(B, Decl(inferTypeParameterConstraints.ts, 8, 40)) |
| 29 | +>B : Symbol(B, Decl(inferTypeParameterConstraints.ts, 8, 40)) |
| 30 | + |
| 31 | +// Repro from #42636 |
| 32 | + |
| 33 | +type Constrain<T extends C, C> = unknown; |
| 34 | +>Constrain : Symbol(Constrain, Decl(inferTypeParameterConstraints.ts, 8, 75)) |
| 35 | +>T : Symbol(T, Decl(inferTypeParameterConstraints.ts, 12, 15)) |
| 36 | +>C : Symbol(C, Decl(inferTypeParameterConstraints.ts, 12, 27)) |
| 37 | +>C : Symbol(C, Decl(inferTypeParameterConstraints.ts, 12, 27)) |
| 38 | + |
| 39 | +type Foo<A> = A extends Constrain<infer X, A> ? X : never; |
| 40 | +>Foo : Symbol(Foo, Decl(inferTypeParameterConstraints.ts, 12, 41)) |
| 41 | +>A : Symbol(A, Decl(inferTypeParameterConstraints.ts, 14, 9)) |
| 42 | +>A : Symbol(A, Decl(inferTypeParameterConstraints.ts, 14, 9)) |
| 43 | +>Constrain : Symbol(Constrain, Decl(inferTypeParameterConstraints.ts, 8, 75)) |
| 44 | +>X : Symbol(X, Decl(inferTypeParameterConstraints.ts, 14, 39)) |
| 45 | +>A : Symbol(A, Decl(inferTypeParameterConstraints.ts, 14, 9)) |
| 46 | +>X : Symbol(X, Decl(inferTypeParameterConstraints.ts, 14, 39)) |
| 47 | + |
| 48 | +type T0 = Foo<string>; // string |
| 49 | +>T0 : Symbol(T0, Decl(inferTypeParameterConstraints.ts, 14, 58)) |
| 50 | +>Foo : Symbol(Foo, Decl(inferTypeParameterConstraints.ts, 12, 41)) |
| 51 | + |
0 commit comments