Skip to content

Commit 02fa9c7

Browse files
committed
Adds a test showing 'infer' cannot reference other 'infer' in same 'extends'
1 parent 4a7019e commit 02fa9c7

File tree

5 files changed

+53
-12
lines changed

5 files changed

+53
-12
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
tests/cases/conformance/types/conditional/inferTypesWithExtends2.ts(3,26): error TS2838: All declarations of 'U' must have identical constraints.
22
tests/cases/conformance/types/conditional/inferTypesWithExtends2.ts(3,53): error TS2838: All declarations of 'U' must have identical constraints.
3+
tests/cases/conformance/types/conditional/inferTypesWithExtends2.ts(8,48): error TS2304: Cannot find name 'U'.
34

45

5-
==== tests/cases/conformance/types/conditional/inferTypesWithExtends2.ts (2 errors) ====
6+
==== tests/cases/conformance/types/conditional/inferTypesWithExtends2.ts (3 errors) ====
67
// infer twice with different constraints (same behavior as class/interface)
7-
type X10<T> =
8+
type X1<T> =
89
T extends { a: infer U extends string, b: infer U extends number } ? U :
910
~
1011
!!! error TS2838: All declarations of 'U' must have identical constraints.
1112
~
1213
!!! error TS2838: All declarations of 'U' must have identical constraints.
1314
never;
14-
15+
16+
// infer cannot reference type params in same 'extends' clause
17+
type X2<T> =
18+
T extends { a: infer U, b: infer V extends U } ? [U, V] :
19+
~
20+
!!! error TS2304: Cannot find name 'U'.
21+
never;
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//// [inferTypesWithExtends2.ts]
22
// infer twice with different constraints (same behavior as class/interface)
3-
type X10<T> =
3+
type X1<T> =
44
T extends { a: infer U extends string, b: infer U extends number } ? U :
55
never;
6-
6+
7+
// infer cannot reference type params in same 'extends' clause
8+
type X2<T> =
9+
T extends { a: infer U, b: infer V extends U } ? [U, V] :
10+
never;
711

812
//// [inferTypesWithExtends2.js]
913
"use strict";
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
=== tests/cases/conformance/types/conditional/inferTypesWithExtends2.ts ===
22
// infer twice with different constraints (same behavior as class/interface)
3-
type X10<T> =
4-
>X10 : Symbol(X10, Decl(inferTypesWithExtends2.ts, 0, 0))
5-
>T : Symbol(T, Decl(inferTypesWithExtends2.ts, 1, 9))
3+
type X1<T> =
4+
>X1 : Symbol(X1, Decl(inferTypesWithExtends2.ts, 0, 0))
5+
>T : Symbol(T, Decl(inferTypesWithExtends2.ts, 1, 8))
66

77
T extends { a: infer U extends string, b: infer U extends number } ? U :
8-
>T : Symbol(T, Decl(inferTypesWithExtends2.ts, 1, 9))
8+
>T : Symbol(T, Decl(inferTypesWithExtends2.ts, 1, 8))
99
>a : Symbol(a, Decl(inferTypesWithExtends2.ts, 2, 15))
1010
>U : Symbol(U, Decl(inferTypesWithExtends2.ts, 2, 24), Decl(inferTypesWithExtends2.ts, 2, 51))
1111
>b : Symbol(b, Decl(inferTypesWithExtends2.ts, 2, 42))
@@ -14,3 +14,19 @@ type X10<T> =
1414

1515
never;
1616

17+
// infer cannot reference type params in same 'extends' clause
18+
type X2<T> =
19+
>X2 : Symbol(X2, Decl(inferTypesWithExtends2.ts, 3, 10))
20+
>T : Symbol(T, Decl(inferTypesWithExtends2.ts, 6, 8))
21+
22+
T extends { a: infer U, b: infer V extends U } ? [U, V] :
23+
>T : Symbol(T, Decl(inferTypesWithExtends2.ts, 6, 8))
24+
>a : Symbol(a, Decl(inferTypesWithExtends2.ts, 7, 15))
25+
>U : Symbol(U, Decl(inferTypesWithExtends2.ts, 7, 24))
26+
>b : Symbol(b, Decl(inferTypesWithExtends2.ts, 7, 27))
27+
>V : Symbol(V, Decl(inferTypesWithExtends2.ts, 7, 36))
28+
>U : Symbol(U)
29+
>U : Symbol(U, Decl(inferTypesWithExtends2.ts, 7, 24))
30+
>V : Symbol(V, Decl(inferTypesWithExtends2.ts, 7, 36))
31+
32+
never;
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
=== tests/cases/conformance/types/conditional/inferTypesWithExtends2.ts ===
22
// infer twice with different constraints (same behavior as class/interface)
3-
type X10<T> =
4-
>X10 : X10<T>
3+
type X1<T> =
4+
>X1 : X1<T>
55

66
T extends { a: infer U extends string, b: infer U extends number } ? U :
77
>a : U
88
>b : U
99

1010
never;
1111

12+
// infer cannot reference type params in same 'extends' clause
13+
type X2<T> =
14+
>X2 : X2<T>
15+
16+
T extends { a: infer U, b: infer V extends U } ? [U, V] :
17+
>a : U
18+
>b : V
19+
20+
never;
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// @strict: true
22

33
// infer twice with different constraints (same behavior as class/interface)
4-
type X10<T> =
4+
type X1<T> =
55
T extends { a: infer U extends string, b: infer U extends number } ? U :
66
never;
7+
8+
// infer cannot reference type params in same 'extends' clause
9+
type X2<T> =
10+
T extends { a: infer U, b: infer V extends U } ? [U, V] :
11+
never;

0 commit comments

Comments
 (0)