Skip to content

Commit b2ba275

Browse files
committed
Accept new baselines
1 parent 9cb14fe commit b2ba275

File tree

3 files changed

+219
-0
lines changed

3 files changed

+219
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//// [deferredLookupTypeResolution.ts]
2+
// Repro from #17456
3+
4+
type StringContains<S extends string, L extends string> = (
5+
{ [K in S]: 'true' } &
6+
{ [key: string]: 'false' }
7+
)[L]
8+
9+
type ObjectHasKey<O, L extends string> = StringContains<keyof O, L>
10+
11+
type First<T> = ObjectHasKey<T, '0'>; // Should be deferred
12+
13+
type T1 = ObjectHasKey<{ a: string }, 'a'>; // 'true'
14+
type T2 = ObjectHasKey<{ a: string }, 'b'>; // 'false'
15+
16+
// Verify that mapped type isn't eagerly resolved in type-to-string operation
17+
18+
declare function f1<A extends string, B extends string>(a: A, b: B): { [P in A | B]: any };
19+
20+
function f2<A extends string>(a: A) {
21+
return f1(a, 'x');
22+
}
23+
24+
function f3(x: 'a' | 'b') {
25+
return f2(x);
26+
}
27+
28+
29+
//// [deferredLookupTypeResolution.js]
30+
"use strict";
31+
// Repro from #17456
32+
function f2(a) {
33+
return f1(a, 'x');
34+
}
35+
function f3(x) {
36+
return f2(x);
37+
}
38+
39+
40+
//// [deferredLookupTypeResolution.d.ts]
41+
declare type StringContains<S extends string, L extends string> = ({
42+
[K in S]: 'true';
43+
} & {
44+
[key: string]: 'false';
45+
})[L];
46+
declare type ObjectHasKey<O, L extends string> = StringContains<keyof O, L>;
47+
declare type First<T> = ObjectHasKey<T, '0'>;
48+
declare type T1 = ObjectHasKey<{
49+
a: string;
50+
}, 'a'>;
51+
declare type T2 = ObjectHasKey<{
52+
a: string;
53+
}, 'b'>;
54+
declare function f1<A extends string, B extends string>(a: A, b: B): {
55+
[P in A | B]: any;
56+
};
57+
declare function f2<A extends string>(a: A): {
58+
[P in A | "x"]: any;
59+
};
60+
declare function f3(x: 'a' | 'b'): {
61+
a: any;
62+
b: any;
63+
x: any;
64+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
=== tests/cases/compiler/deferredLookupTypeResolution.ts ===
2+
// Repro from #17456
3+
4+
type StringContains<S extends string, L extends string> = (
5+
>StringContains : Symbol(StringContains, Decl(deferredLookupTypeResolution.ts, 0, 0))
6+
>S : Symbol(S, Decl(deferredLookupTypeResolution.ts, 2, 20))
7+
>L : Symbol(L, Decl(deferredLookupTypeResolution.ts, 2, 37))
8+
9+
{ [K in S]: 'true' } &
10+
>K : Symbol(K, Decl(deferredLookupTypeResolution.ts, 3, 7))
11+
>S : Symbol(S, Decl(deferredLookupTypeResolution.ts, 2, 20))
12+
13+
{ [key: string]: 'false' }
14+
>key : Symbol(key, Decl(deferredLookupTypeResolution.ts, 4, 7))
15+
16+
)[L]
17+
>L : Symbol(L, Decl(deferredLookupTypeResolution.ts, 2, 37))
18+
19+
type ObjectHasKey<O, L extends string> = StringContains<keyof O, L>
20+
>ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution.ts, 5, 6))
21+
>O : Symbol(O, Decl(deferredLookupTypeResolution.ts, 7, 18))
22+
>L : Symbol(L, Decl(deferredLookupTypeResolution.ts, 7, 20))
23+
>StringContains : Symbol(StringContains, Decl(deferredLookupTypeResolution.ts, 0, 0))
24+
>O : Symbol(O, Decl(deferredLookupTypeResolution.ts, 7, 18))
25+
>L : Symbol(L, Decl(deferredLookupTypeResolution.ts, 7, 20))
26+
27+
type First<T> = ObjectHasKey<T, '0'>; // Should be deferred
28+
>First : Symbol(First, Decl(deferredLookupTypeResolution.ts, 7, 67))
29+
>T : Symbol(T, Decl(deferredLookupTypeResolution.ts, 9, 11))
30+
>ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution.ts, 5, 6))
31+
>T : Symbol(T, Decl(deferredLookupTypeResolution.ts, 9, 11))
32+
33+
type T1 = ObjectHasKey<{ a: string }, 'a'>; // 'true'
34+
>T1 : Symbol(T1, Decl(deferredLookupTypeResolution.ts, 9, 37))
35+
>ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution.ts, 5, 6))
36+
>a : Symbol(a, Decl(deferredLookupTypeResolution.ts, 11, 24))
37+
38+
type T2 = ObjectHasKey<{ a: string }, 'b'>; // 'false'
39+
>T2 : Symbol(T2, Decl(deferredLookupTypeResolution.ts, 11, 43))
40+
>ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution.ts, 5, 6))
41+
>a : Symbol(a, Decl(deferredLookupTypeResolution.ts, 12, 24))
42+
43+
// Verify that mapped type isn't eagerly resolved in type-to-string operation
44+
45+
declare function f1<A extends string, B extends string>(a: A, b: B): { [P in A | B]: any };
46+
>f1 : Symbol(f1, Decl(deferredLookupTypeResolution.ts, 12, 43))
47+
>A : Symbol(A, Decl(deferredLookupTypeResolution.ts, 16, 20))
48+
>B : Symbol(B, Decl(deferredLookupTypeResolution.ts, 16, 37))
49+
>a : Symbol(a, Decl(deferredLookupTypeResolution.ts, 16, 56))
50+
>A : Symbol(A, Decl(deferredLookupTypeResolution.ts, 16, 20))
51+
>b : Symbol(b, Decl(deferredLookupTypeResolution.ts, 16, 61))
52+
>B : Symbol(B, Decl(deferredLookupTypeResolution.ts, 16, 37))
53+
>P : Symbol(P, Decl(deferredLookupTypeResolution.ts, 16, 72))
54+
>A : Symbol(A, Decl(deferredLookupTypeResolution.ts, 16, 20))
55+
>B : Symbol(B, Decl(deferredLookupTypeResolution.ts, 16, 37))
56+
57+
function f2<A extends string>(a: A) {
58+
>f2 : Symbol(f2, Decl(deferredLookupTypeResolution.ts, 16, 91))
59+
>A : Symbol(A, Decl(deferredLookupTypeResolution.ts, 18, 12))
60+
>a : Symbol(a, Decl(deferredLookupTypeResolution.ts, 18, 30))
61+
>A : Symbol(A, Decl(deferredLookupTypeResolution.ts, 18, 12))
62+
63+
return f1(a, 'x');
64+
>f1 : Symbol(f1, Decl(deferredLookupTypeResolution.ts, 12, 43))
65+
>a : Symbol(a, Decl(deferredLookupTypeResolution.ts, 18, 30))
66+
}
67+
68+
function f3(x: 'a' | 'b') {
69+
>f3 : Symbol(f3, Decl(deferredLookupTypeResolution.ts, 20, 1))
70+
>x : Symbol(x, Decl(deferredLookupTypeResolution.ts, 22, 12))
71+
72+
return f2(x);
73+
>f2 : Symbol(f2, Decl(deferredLookupTypeResolution.ts, 16, 91))
74+
>x : Symbol(x, Decl(deferredLookupTypeResolution.ts, 22, 12))
75+
}
76+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
=== tests/cases/compiler/deferredLookupTypeResolution.ts ===
2+
// Repro from #17456
3+
4+
type StringContains<S extends string, L extends string> = (
5+
>StringContains : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L]
6+
>S : S
7+
>L : L
8+
9+
{ [K in S]: 'true' } &
10+
>K : K
11+
>S : S
12+
13+
{ [key: string]: 'false' }
14+
>key : string
15+
16+
)[L]
17+
>L : L
18+
19+
type ObjectHasKey<O, L extends string> = StringContains<keyof O, L>
20+
>ObjectHasKey : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L]
21+
>O : O
22+
>L : L
23+
>StringContains : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L]
24+
>O : O
25+
>L : L
26+
27+
type First<T> = ObjectHasKey<T, '0'>; // Should be deferred
28+
>First : ({ [K in S]: "true"; } & { [key: string]: "false"; })["0"]
29+
>T : T
30+
>ObjectHasKey : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L]
31+
>T : T
32+
33+
type T1 = ObjectHasKey<{ a: string }, 'a'>; // 'true'
34+
>T1 : "true"
35+
>ObjectHasKey : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L]
36+
>a : string
37+
38+
type T2 = ObjectHasKey<{ a: string }, 'b'>; // 'false'
39+
>T2 : "false"
40+
>ObjectHasKey : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L]
41+
>a : string
42+
43+
// Verify that mapped type isn't eagerly resolved in type-to-string operation
44+
45+
declare function f1<A extends string, B extends string>(a: A, b: B): { [P in A | B]: any };
46+
>f1 : <A extends string, B extends string>(a: A, b: B) => { [P in A | B]: any; }
47+
>A : A
48+
>B : B
49+
>a : A
50+
>A : A
51+
>b : B
52+
>B : B
53+
>P : P
54+
>A : A
55+
>B : B
56+
57+
function f2<A extends string>(a: A) {
58+
>f2 : <A extends string>(a: A) => { [P in A | B]: any; }
59+
>A : A
60+
>a : A
61+
>A : A
62+
63+
return f1(a, 'x');
64+
>f1(a, 'x') : { [P in A | B]: any; }
65+
>f1 : <A extends string, B extends string>(a: A, b: B) => { [P in A | B]: any; }
66+
>a : A
67+
>'x' : "x"
68+
}
69+
70+
function f3(x: 'a' | 'b') {
71+
>f3 : (x: "a" | "b") => { a: any; b: any; x: any; }
72+
>x : "a" | "b"
73+
74+
return f2(x);
75+
>f2(x) : { a: any; b: any; x: any; }
76+
>f2 : <A extends string>(a: A) => { [P in A | B]: any; }
77+
>x : "a" | "b"
78+
}
79+

0 commit comments

Comments
 (0)