Skip to content

Commit c6b384c

Browse files
authored
Add an extra test case for an aliased mapped type inference (#52742)
1 parent 8f40d56 commit c6b384c

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/compiler/mappedTypeInferenceAliasSubstitution.ts ===
2+
// repro from #31616
3+
4+
const v = { test: { smth: 5 } };
5+
>v : Symbol(v, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 5))
6+
>test : Symbol(test, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 11))
7+
>smth : Symbol(smth, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 19))
8+
9+
type Field<A extends string, R> = { [K in A]: R }
10+
>Field : Symbol(Field, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 32))
11+
>A : Symbol(A, Decl(mappedTypeInferenceAliasSubstitution.ts, 4, 11))
12+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 4, 28))
13+
>K : Symbol(K, Decl(mappedTypeInferenceAliasSubstitution.ts, 4, 37))
14+
>A : Symbol(A, Decl(mappedTypeInferenceAliasSubstitution.ts, 4, 11))
15+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 4, 28))
16+
17+
const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> }): R => ({} as any);
18+
>f : Symbol(f, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 5))
19+
>A : Symbol(A, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 11))
20+
>B : Symbol(B, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 28))
21+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 46))
22+
>x : Symbol(x, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 50))
23+
>K : Symbol(K, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 56))
24+
>A : Symbol(A, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 11))
25+
>Field : Symbol(Field, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 32))
26+
>B : Symbol(B, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 28))
27+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 46))
28+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 46))
29+
30+
const r1 = f(v);
31+
>r1 : Symbol(r1, Decl(mappedTypeInferenceAliasSubstitution.ts, 7, 5))
32+
>f : Symbol(f, Decl(mappedTypeInferenceAliasSubstitution.ts, 6, 5))
33+
>v : Symbol(v, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 5))
34+
35+
const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any);
36+
>g : Symbol(g, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 5))
37+
>A : Symbol(A, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 11))
38+
>B : Symbol(B, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 28))
39+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 46))
40+
>x : Symbol(x, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 50))
41+
>Field : Symbol(Field, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 32))
42+
>A : Symbol(A, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 11))
43+
>Field : Symbol(Field, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 32))
44+
>B : Symbol(B, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 28))
45+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 46))
46+
>R : Symbol(R, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 46))
47+
48+
const r2 = g(v);
49+
>r2 : Symbol(r2, Decl(mappedTypeInferenceAliasSubstitution.ts, 10, 5))
50+
>g : Symbol(g, Decl(mappedTypeInferenceAliasSubstitution.ts, 9, 5))
51+
>v : Symbol(v, Decl(mappedTypeInferenceAliasSubstitution.ts, 2, 5))
52+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== tests/cases/compiler/mappedTypeInferenceAliasSubstitution.ts ===
2+
// repro from #31616
3+
4+
const v = { test: { smth: 5 } };
5+
>v : { test: { smth: number; }; }
6+
>{ test: { smth: 5 } } : { test: { smth: number; }; }
7+
>test : { smth: number; }
8+
>{ smth: 5 } : { smth: number; }
9+
>smth : number
10+
>5 : 5
11+
12+
type Field<A extends string, R> = { [K in A]: R }
13+
>Field : Field<A, R>
14+
15+
const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> }): R => ({} as any);
16+
>f : <A extends string, B extends string, R>(x: { [K in A]: Field<B, R>; }) => R
17+
><A extends string, B extends string, R>(x: { [K in A]: Field<B, R> }): R => ({} as any) : <A extends string, B extends string, R>(x: { [K in A]: Field<B, R>; }) => R
18+
>x : { [K in A]: Field<B, R>; }
19+
>({} as any) : any
20+
>{} as any : any
21+
>{} : {}
22+
23+
const r1 = f(v);
24+
>r1 : number
25+
>f(v) : number
26+
>f : <A extends string, B extends string, R>(x: { [K in A]: Field<B, R>; }) => R
27+
>v : { test: { smth: number; }; }
28+
29+
const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any);
30+
>g : <A extends string, B extends string, R>(x: Field<A, Field<B, R>>) => R
31+
><A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any) : <A extends string, B extends string, R>(x: Field<A, Field<B, R>>) => R
32+
>x : Field<A, Field<B, R>>
33+
>({} as any) : any
34+
>{} as any : any
35+
>{} : {}
36+
37+
const r2 = g(v);
38+
>r2 : number
39+
>g(v) : number
40+
>g : <A extends string, B extends string, R>(x: Field<A, Field<B, R>>) => R
41+
>v : { test: { smth: number; }; }
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// repro from #31616
5+
6+
const v = { test: { smth: 5 } };
7+
8+
type Field<A extends string, R> = { [K in A]: R }
9+
10+
const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> }): R => ({} as any);
11+
const r1 = f(v);
12+
13+
const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any);
14+
const r2 = g(v);

0 commit comments

Comments
 (0)