Skip to content

Commit a15fecd

Browse files
committed
Accept new baselines
1 parent 6262ac8 commit a15fecd

File tree

4 files changed

+297
-0
lines changed

4 files changed

+297
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
tests/cases/compiler/infiniteConstraints.ts(4,37): error TS2536: Type '"val"' cannot be used to index type 'B[Exclude<keyof B, K>]'.
2+
tests/cases/compiler/infiniteConstraints.ts(31,42): error TS2345: Argument of type '{ main: Record<"val", "dup">; alternate: Record<"val", "dup">; }' is not assignable to parameter of type '{ main: never; alternate: never; }'.
3+
Types of property 'main' are incompatible.
4+
Type 'Record<"val", "dup">' is not assignable to type 'never'.
5+
6+
7+
==== tests/cases/compiler/infiniteConstraints.ts (2 errors) ====
8+
// Both of the following types trigger the recursion limiter in getImmediateBaseConstraint
9+
10+
type T1<B extends { [K in keyof B]: Extract<B[Exclude<keyof B, K>], { val: string }>["val"] }> = B;
11+
type T2<B extends { [K in keyof B]: B[Exclude<keyof B, K>]["val"] }> = B;
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
!!! error TS2536: Type '"val"' cannot be used to index type 'B[Exclude<keyof B, K>]'.
14+
15+
// Repros from #22950
16+
17+
type AProp<T extends { a: string }> = T
18+
19+
declare function myBug<
20+
T extends { [K in keyof T]: T[K] extends AProp<infer U> ? U : never }
21+
>(arg: T): T
22+
23+
const out = myBug({obj1: {a: "test"}})
24+
25+
type Value<V extends string = string> = Record<"val", V>;
26+
declare function value<V extends string>(val: V): Value<V>;
27+
28+
declare function ensureNoDuplicates<
29+
T extends {
30+
[K in keyof T]: Extract<T[K], Value>["val"] extends Extract<T[Exclude<keyof T, K>], Value>["val"]
31+
? never
32+
: any
33+
}
34+
>(vals: T): void;
35+
36+
const noError = ensureNoDuplicates({main: value("test"), alternate: value("test2")});
37+
38+
const shouldBeNoError = ensureNoDuplicates({main: value("test")});
39+
40+
const shouldBeError = ensureNoDuplicates({main: value("dup"), alternate: value("dup")});
41+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
!!! error TS2345: Argument of type '{ main: Record<"val", "dup">; alternate: Record<"val", "dup">; }' is not assignable to parameter of type '{ main: never; alternate: never; }'.
43+
!!! error TS2345: Types of property 'main' are incompatible.
44+
!!! error TS2345: Type 'Record<"val", "dup">' is not assignable to type 'never'.
45+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [infiniteConstraints.ts]
2+
// Both of the following types trigger the recursion limiter in getImmediateBaseConstraint
3+
4+
type T1<B extends { [K in keyof B]: Extract<B[Exclude<keyof B, K>], { val: string }>["val"] }> = B;
5+
type T2<B extends { [K in keyof B]: B[Exclude<keyof B, K>]["val"] }> = B;
6+
7+
// Repros from #22950
8+
9+
type AProp<T extends { a: string }> = T
10+
11+
declare function myBug<
12+
T extends { [K in keyof T]: T[K] extends AProp<infer U> ? U : never }
13+
>(arg: T): T
14+
15+
const out = myBug({obj1: {a: "test"}})
16+
17+
type Value<V extends string = string> = Record<"val", V>;
18+
declare function value<V extends string>(val: V): Value<V>;
19+
20+
declare function ensureNoDuplicates<
21+
T extends {
22+
[K in keyof T]: Extract<T[K], Value>["val"] extends Extract<T[Exclude<keyof T, K>], Value>["val"]
23+
? never
24+
: any
25+
}
26+
>(vals: T): void;
27+
28+
const noError = ensureNoDuplicates({main: value("test"), alternate: value("test2")});
29+
30+
const shouldBeNoError = ensureNoDuplicates({main: value("test")});
31+
32+
const shouldBeError = ensureNoDuplicates({main: value("dup"), alternate: value("dup")});
33+
34+
35+
//// [infiniteConstraints.js]
36+
"use strict";
37+
// Both of the following types trigger the recursion limiter in getImmediateBaseConstraint
38+
var out = myBug({ obj1: { a: "test" } });
39+
var noError = ensureNoDuplicates({ main: value("test"), alternate: value("test2") });
40+
var shouldBeNoError = ensureNoDuplicates({ main: value("test") });
41+
var shouldBeError = ensureNoDuplicates({ main: value("dup"), alternate: value("dup") });
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
=== tests/cases/compiler/infiniteConstraints.ts ===
2+
// Both of the following types trigger the recursion limiter in getImmediateBaseConstraint
3+
4+
type T1<B extends { [K in keyof B]: Extract<B[Exclude<keyof B, K>], { val: string }>["val"] }> = B;
5+
>T1 : Symbol(T1, Decl(infiniteConstraints.ts, 0, 0))
6+
>B : Symbol(B, Decl(infiniteConstraints.ts, 2, 8))
7+
>K : Symbol(K, Decl(infiniteConstraints.ts, 2, 21))
8+
>B : Symbol(B, Decl(infiniteConstraints.ts, 2, 8))
9+
>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --))
10+
>B : Symbol(B, Decl(infiniteConstraints.ts, 2, 8))
11+
>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --))
12+
>B : Symbol(B, Decl(infiniteConstraints.ts, 2, 8))
13+
>K : Symbol(K, Decl(infiniteConstraints.ts, 2, 21))
14+
>val : Symbol(val, Decl(infiniteConstraints.ts, 2, 69))
15+
>B : Symbol(B, Decl(infiniteConstraints.ts, 2, 8))
16+
17+
type T2<B extends { [K in keyof B]: B[Exclude<keyof B, K>]["val"] }> = B;
18+
>T2 : Symbol(T2, Decl(infiniteConstraints.ts, 2, 99))
19+
>B : Symbol(B, Decl(infiniteConstraints.ts, 3, 8))
20+
>K : Symbol(K, Decl(infiniteConstraints.ts, 3, 21))
21+
>B : Symbol(B, Decl(infiniteConstraints.ts, 3, 8))
22+
>B : Symbol(B, Decl(infiniteConstraints.ts, 3, 8))
23+
>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --))
24+
>B : Symbol(B, Decl(infiniteConstraints.ts, 3, 8))
25+
>K : Symbol(K, Decl(infiniteConstraints.ts, 3, 21))
26+
>B : Symbol(B, Decl(infiniteConstraints.ts, 3, 8))
27+
28+
// Repros from #22950
29+
30+
type AProp<T extends { a: string }> = T
31+
>AProp : Symbol(AProp, Decl(infiniteConstraints.ts, 3, 73))
32+
>T : Symbol(T, Decl(infiniteConstraints.ts, 7, 11))
33+
>a : Symbol(a, Decl(infiniteConstraints.ts, 7, 22))
34+
>T : Symbol(T, Decl(infiniteConstraints.ts, 7, 11))
35+
36+
declare function myBug<
37+
>myBug : Symbol(myBug, Decl(infiniteConstraints.ts, 7, 39))
38+
39+
T extends { [K in keyof T]: T[K] extends AProp<infer U> ? U : never }
40+
>T : Symbol(T, Decl(infiniteConstraints.ts, 9, 23))
41+
>K : Symbol(K, Decl(infiniteConstraints.ts, 10, 15))
42+
>T : Symbol(T, Decl(infiniteConstraints.ts, 9, 23))
43+
>T : Symbol(T, Decl(infiniteConstraints.ts, 9, 23))
44+
>K : Symbol(K, Decl(infiniteConstraints.ts, 10, 15))
45+
>AProp : Symbol(AProp, Decl(infiniteConstraints.ts, 3, 73))
46+
>U : Symbol(U, Decl(infiniteConstraints.ts, 10, 54))
47+
>U : Symbol(U, Decl(infiniteConstraints.ts, 10, 54))
48+
49+
>(arg: T): T
50+
>arg : Symbol(arg, Decl(infiniteConstraints.ts, 11, 2))
51+
>T : Symbol(T, Decl(infiniteConstraints.ts, 9, 23))
52+
>T : Symbol(T, Decl(infiniteConstraints.ts, 9, 23))
53+
54+
const out = myBug({obj1: {a: "test"}})
55+
>out : Symbol(out, Decl(infiniteConstraints.ts, 13, 5))
56+
>myBug : Symbol(myBug, Decl(infiniteConstraints.ts, 7, 39))
57+
>obj1 : Symbol(obj1, Decl(infiniteConstraints.ts, 13, 19))
58+
>a : Symbol(a, Decl(infiniteConstraints.ts, 13, 26))
59+
60+
type Value<V extends string = string> = Record<"val", V>;
61+
>Value : Symbol(Value, Decl(infiniteConstraints.ts, 13, 38))
62+
>V : Symbol(V, Decl(infiniteConstraints.ts, 15, 11))
63+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
64+
>V : Symbol(V, Decl(infiniteConstraints.ts, 15, 11))
65+
66+
declare function value<V extends string>(val: V): Value<V>;
67+
>value : Symbol(value, Decl(infiniteConstraints.ts, 15, 57))
68+
>V : Symbol(V, Decl(infiniteConstraints.ts, 16, 23))
69+
>val : Symbol(val, Decl(infiniteConstraints.ts, 16, 41))
70+
>V : Symbol(V, Decl(infiniteConstraints.ts, 16, 23))
71+
>Value : Symbol(Value, Decl(infiniteConstraints.ts, 13, 38))
72+
>V : Symbol(V, Decl(infiniteConstraints.ts, 16, 23))
73+
74+
declare function ensureNoDuplicates<
75+
>ensureNoDuplicates : Symbol(ensureNoDuplicates, Decl(infiniteConstraints.ts, 16, 59))
76+
77+
T extends {
78+
>T : Symbol(T, Decl(infiniteConstraints.ts, 18, 36))
79+
80+
[K in keyof T]: Extract<T[K], Value>["val"] extends Extract<T[Exclude<keyof T, K>], Value>["val"]
81+
>K : Symbol(K, Decl(infiniteConstraints.ts, 20, 5))
82+
>T : Symbol(T, Decl(infiniteConstraints.ts, 18, 36))
83+
>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --))
84+
>T : Symbol(T, Decl(infiniteConstraints.ts, 18, 36))
85+
>K : Symbol(K, Decl(infiniteConstraints.ts, 20, 5))
86+
>Value : Symbol(Value, Decl(infiniteConstraints.ts, 13, 38))
87+
>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --))
88+
>T : Symbol(T, Decl(infiniteConstraints.ts, 18, 36))
89+
>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --))
90+
>T : Symbol(T, Decl(infiniteConstraints.ts, 18, 36))
91+
>K : Symbol(K, Decl(infiniteConstraints.ts, 20, 5))
92+
>Value : Symbol(Value, Decl(infiniteConstraints.ts, 13, 38))
93+
94+
? never
95+
: any
96+
}
97+
>(vals: T): void;
98+
>vals : Symbol(vals, Decl(infiniteConstraints.ts, 24, 2))
99+
>T : Symbol(T, Decl(infiniteConstraints.ts, 18, 36))
100+
101+
const noError = ensureNoDuplicates({main: value("test"), alternate: value("test2")});
102+
>noError : Symbol(noError, Decl(infiniteConstraints.ts, 26, 5))
103+
>ensureNoDuplicates : Symbol(ensureNoDuplicates, Decl(infiniteConstraints.ts, 16, 59))
104+
>main : Symbol(main, Decl(infiniteConstraints.ts, 26, 36))
105+
>value : Symbol(value, Decl(infiniteConstraints.ts, 15, 57))
106+
>alternate : Symbol(alternate, Decl(infiniteConstraints.ts, 26, 56))
107+
>value : Symbol(value, Decl(infiniteConstraints.ts, 15, 57))
108+
109+
const shouldBeNoError = ensureNoDuplicates({main: value("test")});
110+
>shouldBeNoError : Symbol(shouldBeNoError, Decl(infiniteConstraints.ts, 28, 5))
111+
>ensureNoDuplicates : Symbol(ensureNoDuplicates, Decl(infiniteConstraints.ts, 16, 59))
112+
>main : Symbol(main, Decl(infiniteConstraints.ts, 28, 44))
113+
>value : Symbol(value, Decl(infiniteConstraints.ts, 15, 57))
114+
115+
const shouldBeError = ensureNoDuplicates({main: value("dup"), alternate: value("dup")});
116+
>shouldBeError : Symbol(shouldBeError, Decl(infiniteConstraints.ts, 30, 5))
117+
>ensureNoDuplicates : Symbol(ensureNoDuplicates, Decl(infiniteConstraints.ts, 16, 59))
118+
>main : Symbol(main, Decl(infiniteConstraints.ts, 30, 42))
119+
>value : Symbol(value, Decl(infiniteConstraints.ts, 15, 57))
120+
>alternate : Symbol(alternate, Decl(infiniteConstraints.ts, 30, 61))
121+
>value : Symbol(value, Decl(infiniteConstraints.ts, 15, 57))
122+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
=== tests/cases/compiler/infiniteConstraints.ts ===
2+
// Both of the following types trigger the recursion limiter in getImmediateBaseConstraint
3+
4+
type T1<B extends { [K in keyof B]: Extract<B[Exclude<keyof B, K>], { val: string }>["val"] }> = B;
5+
>T1 : B
6+
>val : string
7+
8+
type T2<B extends { [K in keyof B]: B[Exclude<keyof B, K>]["val"] }> = B;
9+
>T2 : B
10+
11+
// Repros from #22950
12+
13+
type AProp<T extends { a: string }> = T
14+
>AProp : T
15+
>a : string
16+
17+
declare function myBug<
18+
>myBug : <T extends { [K in keyof T]: T[K]; }>(arg: T) => T
19+
20+
T extends { [K in keyof T]: T[K] extends AProp<infer U> ? U : never }
21+
>(arg: T): T
22+
>arg : T
23+
24+
const out = myBug({obj1: {a: "test"}})
25+
>out : { obj1: { a: string; }; }
26+
>myBug({obj1: {a: "test"}}) : { obj1: { a: string; }; }
27+
>myBug : <T extends { [K in keyof T]: T[K]; }>(arg: T) => T
28+
>{obj1: {a: "test"}} : { obj1: { a: string; }; }
29+
>obj1 : { a: string; }
30+
>{a: "test"} : { a: string; }
31+
>a : string
32+
>"test" : "test"
33+
34+
type Value<V extends string = string> = Record<"val", V>;
35+
>Value : Record<"val", V>
36+
37+
declare function value<V extends string>(val: V): Value<V>;
38+
>value : <V extends string>(val: V) => Record<"val", V>
39+
>val : V
40+
41+
declare function ensureNoDuplicates<
42+
>ensureNoDuplicates : <T extends { [K in keyof T]: Extract<T[K], Record<"val", string>>["val"] extends Extract<T[Exclude<keyof T, K>], Record<"val", string>>["val"] ? never : any; }>(vals: T) => void
43+
44+
T extends {
45+
[K in keyof T]: Extract<T[K], Value>["val"] extends Extract<T[Exclude<keyof T, K>], Value>["val"]
46+
? never
47+
: any
48+
}
49+
>(vals: T): void;
50+
>vals : T
51+
52+
const noError = ensureNoDuplicates({main: value("test"), alternate: value("test2")});
53+
>noError : void
54+
>ensureNoDuplicates({main: value("test"), alternate: value("test2")}) : void
55+
>ensureNoDuplicates : <T extends { [K in keyof T]: Extract<T[K], Record<"val", string>>["val"] extends Extract<T[Exclude<keyof T, K>], Record<"val", string>>["val"] ? never : any; }>(vals: T) => void
56+
>{main: value("test"), alternate: value("test2")} : { main: Record<"val", "test">; alternate: Record<"val", "test2">; }
57+
>main : Record<"val", "test">
58+
>value("test") : Record<"val", "test">
59+
>value : <V extends string>(val: V) => Record<"val", V>
60+
>"test" : "test"
61+
>alternate : Record<"val", "test2">
62+
>value("test2") : Record<"val", "test2">
63+
>value : <V extends string>(val: V) => Record<"val", V>
64+
>"test2" : "test2"
65+
66+
const shouldBeNoError = ensureNoDuplicates({main: value("test")});
67+
>shouldBeNoError : void
68+
>ensureNoDuplicates({main: value("test")}) : void
69+
>ensureNoDuplicates : <T extends { [K in keyof T]: Extract<T[K], Record<"val", string>>["val"] extends Extract<T[Exclude<keyof T, K>], Record<"val", string>>["val"] ? never : any; }>(vals: T) => void
70+
>{main: value("test")} : { main: Record<"val", "test">; }
71+
>main : Record<"val", "test">
72+
>value("test") : Record<"val", "test">
73+
>value : <V extends string>(val: V) => Record<"val", V>
74+
>"test" : "test"
75+
76+
const shouldBeError = ensureNoDuplicates({main: value("dup"), alternate: value("dup")});
77+
>shouldBeError : any
78+
>ensureNoDuplicates({main: value("dup"), alternate: value("dup")}) : any
79+
>ensureNoDuplicates : <T extends { [K in keyof T]: Extract<T[K], Record<"val", string>>["val"] extends Extract<T[Exclude<keyof T, K>], Record<"val", string>>["val"] ? never : any; }>(vals: T) => void
80+
>{main: value("dup"), alternate: value("dup")} : { main: Record<"val", "dup">; alternate: Record<"val", "dup">; }
81+
>main : Record<"val", "dup">
82+
>value("dup") : Record<"val", "dup">
83+
>value : <V extends string>(val: V) => Record<"val", V>
84+
>"dup" : "dup"
85+
>alternate : Record<"val", "dup">
86+
>value("dup") : Record<"val", "dup">
87+
>value : <V extends string>(val: V) => Record<"val", V>
88+
>"dup" : "dup"
89+

0 commit comments

Comments
 (0)