Skip to content

Commit 7c4d923

Browse files
committed
Accept new baselines
1 parent dd64bf8 commit 7c4d923

4 files changed

+895
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
tests/cases/compiler/recursiveConditionalTypes.ts(16,11): error TS2589: Type instantiation is excessively deep and possibly infinite.
2+
tests/cases/compiler/recursiveConditionalTypes.ts(20,5): error TS2322: Type 'Awaited<T>' is not assignable to type 'Awaited<U>'.
3+
Type 'T' is not assignable to type 'U'.
4+
'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
5+
tests/cases/compiler/recursiveConditionalTypes.ts(21,5): error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
6+
tests/cases/compiler/recursiveConditionalTypes.ts(22,5): error TS2322: Type 'Awaited<T>' is not assignable to type 'T'.
7+
'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited<T>'.
8+
Type 'T | (T extends PromiseLike<infer U> ? Awaited<U> : T)' is not assignable to type 'T'.
9+
'T' could be instantiated with an arbitrary type which could be unrelated to 'T | (T extends PromiseLike<infer U> ? Awaited<U> : T)'.
10+
Type 'T extends PromiseLike<infer U> ? Awaited<U> : T' is not assignable to type 'T'.
11+
'T' could be instantiated with an arbitrary type which could be unrelated to 'T extends PromiseLike<infer U> ? Awaited<U> : T'.
12+
Type 'unknown' is not assignable to type 'T'.
13+
'T' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.
14+
tests/cases/compiler/recursiveConditionalTypes.ts(35,11): error TS2589: Type instantiation is excessively deep and possibly infinite.
15+
tests/cases/compiler/recursiveConditionalTypes.ts(46,12): error TS2589: Type instantiation is excessively deep and possibly infinite.
16+
tests/cases/compiler/recursiveConditionalTypes.ts(49,5): error TS2322: Type 'TupleOf<number, M>' is not assignable to type 'TupleOf<number, N>'.
17+
Type 'number extends M ? number[] : _TupleOf<number, M, []>' is not assignable to type 'TupleOf<number, N>'.
18+
Type 'number[] | _TupleOf<number, M, []>' is not assignable to type 'TupleOf<number, N>'.
19+
Type 'number[]' is not assignable to type 'TupleOf<number, N>'.
20+
tests/cases/compiler/recursiveConditionalTypes.ts(50,5): error TS2322: Type 'TupleOf<number, N>' is not assignable to type 'TupleOf<number, M>'.
21+
Type 'number extends N ? number[] : _TupleOf<number, N, []>' is not assignable to type 'TupleOf<number, M>'.
22+
Type 'number[] | _TupleOf<number, N, []>' is not assignable to type 'TupleOf<number, M>'.
23+
Type 'number[]' is not assignable to type 'TupleOf<number, M>'.
24+
tests/cases/compiler/recursiveConditionalTypes.ts(89,5): error TS2589: Type instantiation is excessively deep and possibly infinite.
25+
tests/cases/compiler/recursiveConditionalTypes.ts(89,9): error TS2345: Argument of type 'Grow2<[], T>' is not assignable to parameter of type 'Grow1<[], T>'.
26+
Type '[] | Grow2<[string], T>' is not assignable to type 'Grow1<[], T>'.
27+
Type '[]' is not assignable to type 'Grow1<[], T>'.
28+
Type 'Grow2<[string], T>' is not assignable to type 'Grow1<[number], T>'.
29+
Type '[string] | Grow2<[string, string], T>' is not assignable to type 'Grow1<[number], T>'.
30+
Type '[string]' is not assignable to type 'Grow1<[number], T>'.
31+
Type '[string]' is not assignable to type '[number]'.
32+
Type 'string' is not assignable to type 'number'.
33+
34+
35+
==== tests/cases/compiler/recursiveConditionalTypes.ts (10 errors) ====
36+
// Awaiting promises
37+
38+
type Awaited<T> =
39+
T extends null | undefined ? T :
40+
T extends PromiseLike<infer U> ? Awaited<U> :
41+
T;
42+
43+
type MyPromise<T> = {
44+
then<U>(f: ((value: T) => U | MyPromise<U>) | null | undefined): MyPromise<U>;
45+
}
46+
47+
type InfinitePromise<T> = Promise<InfinitePromise<T>>;
48+
49+
type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
50+
type P1 = Awaited<any>;
51+
type P2 = Awaited<InfinitePromise<number>>; // Error
52+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
54+
55+
function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) {
56+
ta = ua;
57+
ua = ta; // Error
58+
~~
59+
!!! error TS2322: Type 'Awaited<T>' is not assignable to type 'Awaited<U>'.
60+
!!! error TS2322: Type 'T' is not assignable to type 'U'.
61+
!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
62+
ta = tx; // Error
63+
~~
64+
!!! error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
65+
tx = ta; // Error
66+
~~
67+
!!! error TS2322: Type 'Awaited<T>' is not assignable to type 'T'.
68+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited<T>'.
69+
!!! error TS2322: Type 'T | (T extends PromiseLike<infer U> ? Awaited<U> : T)' is not assignable to type 'T'.
70+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'T | (T extends PromiseLike<infer U> ? Awaited<U> : T)'.
71+
!!! error TS2322: Type 'T extends PromiseLike<infer U> ? Awaited<U> : T' is not assignable to type 'T'.
72+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'T extends PromiseLike<infer U> ? Awaited<U> : T'.
73+
!!! error TS2322: Type 'unknown' is not assignable to type 'T'.
74+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.
75+
}
76+
77+
// Flattening arrays
78+
79+
type Flatten<T extends readonly unknown[]> = T extends unknown[] ? _Flatten<T>[] : readonly _Flatten<T>[];
80+
type _Flatten<T> = T extends readonly (infer U)[] ? _Flatten<U> : T;
81+
82+
type InfiniteArray<T> = InfiniteArray<T>[];
83+
84+
type B0 = Flatten<string[][][]>;
85+
type B1 = Flatten<string[][] | readonly (number[] | boolean[][])[]>;
86+
type B2 = Flatten<InfiniteArray<string>>;
87+
type B3 = B2[0]; // Error
88+
~~~~~
89+
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
90+
91+
// Repeating tuples
92+
93+
type TupleOf<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
94+
type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
95+
96+
type TT0 = TupleOf<string, 4>;
97+
type TT1 = TupleOf<number, 0 | 2 | 4>;
98+
type TT2 = TupleOf<number, number>;
99+
type TT3 = TupleOf<number, any>;
100+
type TT4 = TupleOf<number, 100>; // Depth error
101+
~~~~~~~~~~~~~~~~~~~~
102+
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
103+
104+
function f22<N extends number, M extends N>(tn: TupleOf<number, N>, tm: TupleOf<number, M>) {
105+
tn = tm;
106+
~~
107+
!!! error TS2322: Type 'TupleOf<number, M>' is not assignable to type 'TupleOf<number, N>'.
108+
!!! error TS2322: Type 'number extends M ? number[] : _TupleOf<number, M, []>' is not assignable to type 'TupleOf<number, N>'.
109+
!!! error TS2322: Type 'number[] | _TupleOf<number, M, []>' is not assignable to type 'TupleOf<number, N>'.
110+
!!! error TS2322: Type 'number[]' is not assignable to type 'TupleOf<number, N>'.
111+
tm = tn;
112+
~~
113+
!!! error TS2322: Type 'TupleOf<number, N>' is not assignable to type 'TupleOf<number, M>'.
114+
!!! error TS2322: Type 'number extends N ? number[] : _TupleOf<number, N, []>' is not assignable to type 'TupleOf<number, M>'.
115+
!!! error TS2322: Type 'number[] | _TupleOf<number, N, []>' is not assignable to type 'TupleOf<number, M>'.
116+
!!! error TS2322: Type 'number[]' is not assignable to type 'TupleOf<number, M>'.
117+
}
118+
119+
declare function f23<T>(t: TupleOf<T, 3>): T;
120+
121+
f23(['a', 'b', 'c']); // string
122+
123+
// Inference from nested instantiations of same generic types
124+
125+
type Box1<T> = { value: T };
126+
type Box2<T> = { value: T };
127+
128+
declare function foo<T>(x: Box1<Box1<T>>): T;
129+
130+
declare let z: Box2<Box2<string>>;
131+
132+
foo(z); // string
133+
134+
// Intersect tuple element types
135+
136+
type Intersect<U extends any[], R = unknown> = U extends [infer H, ...infer T] ? Intersect<T, R & H> : R;
137+
138+
type QQ = Intersect<[string[], number[], 7]>;
139+
140+
// Infer between structurally identical recursive conditional types
141+
142+
type Unpack1<T> = T extends (infer U)[] ? Unpack1<U> : T;
143+
type Unpack2<T> = T extends (infer U)[] ? Unpack2<U> : T;
144+
145+
function f20<T, U extends T>(x: Unpack1<T>, y: Unpack2<T>) {
146+
x = y;
147+
y = x;
148+
f20(y, x);
149+
}
150+
151+
type Grow1<T extends unknown[], N extends number> = T['length'] extends N ? T : Grow1<[number, ...T], N>;
152+
type Grow2<T extends unknown[], N extends number> = T['length'] extends N ? T : Grow2<[string, ...T], N>;
153+
154+
function f21<T extends number>(x: Grow1<[], T>, y: Grow2<[], T>) {
155+
f21(y, x); // Error
156+
~~~~~~~~~
157+
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
158+
~
159+
!!! error TS2345: Argument of type 'Grow2<[], T>' is not assignable to parameter of type 'Grow1<[], T>'.
160+
!!! error TS2345: Type '[] | Grow2<[string], T>' is not assignable to type 'Grow1<[], T>'.
161+
!!! error TS2345: Type '[]' is not assignable to type 'Grow1<[], T>'.
162+
!!! error TS2345: Type 'Grow2<[string], T>' is not assignable to type 'Grow1<[number], T>'.
163+
!!! error TS2345: Type '[string] | Grow2<[string, string], T>' is not assignable to type 'Grow1<[number], T>'.
164+
!!! error TS2345: Type '[string]' is not assignable to type 'Grow1<[number], T>'.
165+
!!! error TS2345: Type '[string]' is not assignable to type '[number]'.
166+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
167+
}
168+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//// [recursiveConditionalTypes.ts]
2+
// Awaiting promises
3+
4+
type Awaited<T> =
5+
T extends null | undefined ? T :
6+
T extends PromiseLike<infer U> ? Awaited<U> :
7+
T;
8+
9+
type MyPromise<T> = {
10+
then<U>(f: ((value: T) => U | MyPromise<U>) | null | undefined): MyPromise<U>;
11+
}
12+
13+
type InfinitePromise<T> = Promise<InfinitePromise<T>>;
14+
15+
type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
16+
type P1 = Awaited<any>;
17+
type P2 = Awaited<InfinitePromise<number>>; // Error
18+
19+
function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>) {
20+
ta = ua;
21+
ua = ta; // Error
22+
ta = tx; // Error
23+
tx = ta; // Error
24+
}
25+
26+
// Flattening arrays
27+
28+
type Flatten<T extends readonly unknown[]> = T extends unknown[] ? _Flatten<T>[] : readonly _Flatten<T>[];
29+
type _Flatten<T> = T extends readonly (infer U)[] ? _Flatten<U> : T;
30+
31+
type InfiniteArray<T> = InfiniteArray<T>[];
32+
33+
type B0 = Flatten<string[][][]>;
34+
type B1 = Flatten<string[][] | readonly (number[] | boolean[][])[]>;
35+
type B2 = Flatten<InfiniteArray<string>>;
36+
type B3 = B2[0]; // Error
37+
38+
// Repeating tuples
39+
40+
type TupleOf<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
41+
type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
42+
43+
type TT0 = TupleOf<string, 4>;
44+
type TT1 = TupleOf<number, 0 | 2 | 4>;
45+
type TT2 = TupleOf<number, number>;
46+
type TT3 = TupleOf<number, any>;
47+
type TT4 = TupleOf<number, 100>; // Depth error
48+
49+
function f22<N extends number, M extends N>(tn: TupleOf<number, N>, tm: TupleOf<number, M>) {
50+
tn = tm;
51+
tm = tn;
52+
}
53+
54+
declare function f23<T>(t: TupleOf<T, 3>): T;
55+
56+
f23(['a', 'b', 'c']); // string
57+
58+
// Inference from nested instantiations of same generic types
59+
60+
type Box1<T> = { value: T };
61+
type Box2<T> = { value: T };
62+
63+
declare function foo<T>(x: Box1<Box1<T>>): T;
64+
65+
declare let z: Box2<Box2<string>>;
66+
67+
foo(z); // string
68+
69+
// Intersect tuple element types
70+
71+
type Intersect<U extends any[], R = unknown> = U extends [infer H, ...infer T] ? Intersect<T, R & H> : R;
72+
73+
type QQ = Intersect<[string[], number[], 7]>;
74+
75+
// Infer between structurally identical recursive conditional types
76+
77+
type Unpack1<T> = T extends (infer U)[] ? Unpack1<U> : T;
78+
type Unpack2<T> = T extends (infer U)[] ? Unpack2<U> : T;
79+
80+
function f20<T, U extends T>(x: Unpack1<T>, y: Unpack2<T>) {
81+
x = y;
82+
y = x;
83+
f20(y, x);
84+
}
85+
86+
type Grow1<T extends unknown[], N extends number> = T['length'] extends N ? T : Grow1<[number, ...T], N>;
87+
type Grow2<T extends unknown[], N extends number> = T['length'] extends N ? T : Grow2<[string, ...T], N>;
88+
89+
function f21<T extends number>(x: Grow1<[], T>, y: Grow2<[], T>) {
90+
f21(y, x); // Error
91+
}
92+
93+
94+
//// [recursiveConditionalTypes.js]
95+
"use strict";
96+
// Awaiting promises
97+
function f11(tx, ta, ux, ua) {
98+
ta = ua;
99+
ua = ta; // Error
100+
ta = tx; // Error
101+
tx = ta; // Error
102+
}
103+
function f22(tn, tm) {
104+
tn = tm;
105+
tm = tn;
106+
}
107+
f23(['a', 'b', 'c']); // string
108+
foo(z); // string
109+
function f20(x, y) {
110+
x = y;
111+
y = x;
112+
f20(y, x);
113+
}
114+
function f21(x, y) {
115+
f21(y, x); // Error
116+
}
117+
118+
119+
//// [recursiveConditionalTypes.d.ts]
120+
declare type Awaited<T> = T extends null | undefined ? T : T extends PromiseLike<infer U> ? Awaited<U> : T;
121+
declare type MyPromise<T> = {
122+
then<U>(f: ((value: T) => U | MyPromise<U>) | null | undefined): MyPromise<U>;
123+
};
124+
declare type InfinitePromise<T> = Promise<InfinitePromise<T>>;
125+
declare type P0 = Awaited<Promise<string | Promise<MyPromise<number> | null> | undefined>>;
126+
declare type P1 = Awaited<any>;
127+
declare type P2 = Awaited<InfinitePromise<number>>;
128+
declare function f11<T, U extends T>(tx: T, ta: Awaited<T>, ux: U, ua: Awaited<U>): void;
129+
declare type Flatten<T extends readonly unknown[]> = T extends unknown[] ? _Flatten<T>[] : readonly _Flatten<T>[];
130+
declare type _Flatten<T> = T extends readonly (infer U)[] ? _Flatten<U> : T;
131+
declare type InfiniteArray<T> = InfiniteArray<T>[];
132+
declare type B0 = Flatten<string[][][]>;
133+
declare type B1 = Flatten<string[][] | readonly (number[] | boolean[][])[]>;
134+
declare type B2 = Flatten<InfiniteArray<string>>;
135+
declare type B3 = B2[0];
136+
declare type TupleOf<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
137+
declare type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
138+
declare type TT0 = TupleOf<string, 4>;
139+
declare type TT1 = TupleOf<number, 0 | 2 | 4>;
140+
declare type TT2 = TupleOf<number, number>;
141+
declare type TT3 = TupleOf<number, any>;
142+
declare type TT4 = TupleOf<number, 100>;
143+
declare function f22<N extends number, M extends N>(tn: TupleOf<number, N>, tm: TupleOf<number, M>): void;
144+
declare function f23<T>(t: TupleOf<T, 3>): T;
145+
declare type Box1<T> = {
146+
value: T;
147+
};
148+
declare type Box2<T> = {
149+
value: T;
150+
};
151+
declare function foo<T>(x: Box1<Box1<T>>): T;
152+
declare let z: Box2<Box2<string>>;
153+
declare type Intersect<U extends any[], R = unknown> = U extends [infer H, ...infer T] ? Intersect<T, R & H> : R;
154+
declare type QQ = Intersect<[string[], number[], 7]>;
155+
declare type Unpack1<T> = T extends (infer U)[] ? Unpack1<U> : T;
156+
declare type Unpack2<T> = T extends (infer U)[] ? Unpack2<U> : T;
157+
declare function f20<T, U extends T>(x: Unpack1<T>, y: Unpack2<T>): void;
158+
declare type Grow1<T extends unknown[], N extends number> = T['length'] extends N ? T : Grow1<[number, ...T], N>;
159+
declare type Grow2<T extends unknown[], N extends number> = T['length'] extends N ? T : Grow2<[string, ...T], N>;
160+
declare function f21<T extends number>(x: Grow1<[], T>, y: Grow2<[], T>): void;

0 commit comments

Comments
 (0)