Skip to content

Commit f68bcc3

Browse files
committed
add test
1 parent 2f7d409 commit f68bcc3

File tree

4 files changed

+388
-1
lines changed

4 files changed

+388
-1
lines changed

tests/baselines/reference/mappedTypeRelationships2.errors.txt

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
mappedTypeRelationships2.ts(21,38): error TS2344: Type 'ABC' does not satisfy the constraint 'WithNumber<Record<keyof T, any>>'.
2+
mappedTypeRelationships2.ts(67,5): error TS2353: Object literal may only specify known properties, and 'special' does not exist in type 'Lookup<"common">'.
3+
mappedTypeRelationships2.ts(78,9): error TS2322: Type '{ field1: undefined; field2: undefined; special: 32; }' is not assignable to type 'Lookup<K>'.
24

35

4-
==== mappedTypeRelationships2.ts (1 errors) ====
6+
==== mappedTypeRelationships2.ts (3 errors) ====
57
// https://github.com/microsoft/TypeScript/issues/62717
68

79
type Alias1<T extends object, U extends { [K in keyof T]?: any }> = U;
@@ -36,5 +38,61 @@ mappedTypeRelationships2.ts(21,38): error TS2344: Type 'ABC' does not satisfy th
3638
type Test9 = Alias5<AB, ABC>; // ok
3739
type Test10<T extends AB> = Alias5<T, ABC>; // ok
3840

41+
// part of https://github.com/microsoft/TypeScript/issues/62770
42+
43+
interface WithCommon {
44+
field1: number;
45+
field2: string;
46+
}
47+
48+
interface WithSpecial extends WithCommon {
49+
special: number;
50+
}
51+
52+
interface SpecialLookup {
53+
special: WithSpecial;
54+
}
55+
56+
interface CommonLookup extends SpecialLookup {
57+
common: WithCommon;
58+
}
59+
60+
type Lookup<Name extends keyof CommonLookup> = {
61+
[K in keyof CommonLookup[Name]]?: CommonLookup[Name][K];
62+
};
63+
function someName<K extends keyof SpecialLookup>(): void {
64+
// ok
65+
const works1: Lookup<"special"> = {
66+
field1: 1,
67+
field2: "common",
68+
special: 203,
69+
};
70+
71+
// error
72+
const works2: Lookup<"common"> = {
73+
field1: 5,
74+
field2: "something",
75+
special: 32,
76+
~~~~~~~
77+
!!! error TS2353: Object literal may only specify known properties, and 'special' does not exist in type 'Lookup<"common">'.
78+
};
79+
80+
// ok
81+
const works3: Lookup<K> = {
82+
special: undefined,
83+
field1: undefined,
84+
field2: undefined,
85+
};
86+
87+
// error
88+
const works4: Lookup<K> = {
89+
~~~~~~
90+
!!! error TS2322: Type '{ field1: undefined; field2: undefined; special: 32; }' is not assignable to type 'Lookup<K>'.
91+
field1: undefined,
92+
field2: undefined,
93+
special: 32,
94+
};
95+
}
96+
3997
export {};
4098

tests/baselines/reference/mappedTypeRelationships2.symbols

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,133 @@ type Test10<T extends AB> = Alias5<T, ABC>; // ok
142142
>T : Symbol(T, Decl(mappedTypeRelationships2.ts, 30, 12))
143143
>ABC : Symbol(ABC, Decl(mappedTypeRelationships2.ts, 15, 78))
144144

145+
// part of https://github.com/microsoft/TypeScript/issues/62770
146+
147+
interface WithCommon {
148+
>WithCommon : Symbol(WithCommon, Decl(mappedTypeRelationships2.ts, 30, 43))
149+
150+
field1: number;
151+
>field1 : Symbol(WithCommon.field1, Decl(mappedTypeRelationships2.ts, 34, 22))
152+
153+
field2: string;
154+
>field2 : Symbol(WithCommon.field2, Decl(mappedTypeRelationships2.ts, 35, 17))
155+
}
156+
157+
interface WithSpecial extends WithCommon {
158+
>WithSpecial : Symbol(WithSpecial, Decl(mappedTypeRelationships2.ts, 37, 1))
159+
>WithCommon : Symbol(WithCommon, Decl(mappedTypeRelationships2.ts, 30, 43))
160+
161+
special: number;
162+
>special : Symbol(WithSpecial.special, Decl(mappedTypeRelationships2.ts, 39, 42))
163+
}
164+
165+
interface SpecialLookup {
166+
>SpecialLookup : Symbol(SpecialLookup, Decl(mappedTypeRelationships2.ts, 41, 1))
167+
168+
special: WithSpecial;
169+
>special : Symbol(SpecialLookup.special, Decl(mappedTypeRelationships2.ts, 43, 25))
170+
>WithSpecial : Symbol(WithSpecial, Decl(mappedTypeRelationships2.ts, 37, 1))
171+
}
172+
173+
interface CommonLookup extends SpecialLookup {
174+
>CommonLookup : Symbol(CommonLookup, Decl(mappedTypeRelationships2.ts, 45, 1))
175+
>SpecialLookup : Symbol(SpecialLookup, Decl(mappedTypeRelationships2.ts, 41, 1))
176+
177+
common: WithCommon;
178+
>common : Symbol(CommonLookup.common, Decl(mappedTypeRelationships2.ts, 47, 46))
179+
>WithCommon : Symbol(WithCommon, Decl(mappedTypeRelationships2.ts, 30, 43))
180+
}
181+
182+
type Lookup<Name extends keyof CommonLookup> = {
183+
>Lookup : Symbol(Lookup, Decl(mappedTypeRelationships2.ts, 49, 1))
184+
>Name : Symbol(Name, Decl(mappedTypeRelationships2.ts, 51, 12))
185+
>CommonLookup : Symbol(CommonLookup, Decl(mappedTypeRelationships2.ts, 45, 1))
186+
187+
[K in keyof CommonLookup[Name]]?: CommonLookup[Name][K];
188+
>K : Symbol(K, Decl(mappedTypeRelationships2.ts, 52, 3))
189+
>CommonLookup : Symbol(CommonLookup, Decl(mappedTypeRelationships2.ts, 45, 1))
190+
>Name : Symbol(Name, Decl(mappedTypeRelationships2.ts, 51, 12))
191+
>CommonLookup : Symbol(CommonLookup, Decl(mappedTypeRelationships2.ts, 45, 1))
192+
>Name : Symbol(Name, Decl(mappedTypeRelationships2.ts, 51, 12))
193+
>K : Symbol(K, Decl(mappedTypeRelationships2.ts, 52, 3))
194+
195+
};
196+
function someName<K extends keyof SpecialLookup>(): void {
197+
>someName : Symbol(someName, Decl(mappedTypeRelationships2.ts, 53, 2))
198+
>K : Symbol(K, Decl(mappedTypeRelationships2.ts, 54, 18))
199+
>SpecialLookup : Symbol(SpecialLookup, Decl(mappedTypeRelationships2.ts, 41, 1))
200+
201+
// ok
202+
const works1: Lookup<"special"> = {
203+
>works1 : Symbol(works1, Decl(mappedTypeRelationships2.ts, 56, 7))
204+
>Lookup : Symbol(Lookup, Decl(mappedTypeRelationships2.ts, 49, 1))
205+
206+
field1: 1,
207+
>field1 : Symbol(field1, Decl(mappedTypeRelationships2.ts, 56, 37))
208+
209+
field2: "common",
210+
>field2 : Symbol(field2, Decl(mappedTypeRelationships2.ts, 57, 14))
211+
212+
special: 203,
213+
>special : Symbol(special, Decl(mappedTypeRelationships2.ts, 58, 21))
214+
215+
};
216+
217+
// error
218+
const works2: Lookup<"common"> = {
219+
>works2 : Symbol(works2, Decl(mappedTypeRelationships2.ts, 63, 7))
220+
>Lookup : Symbol(Lookup, Decl(mappedTypeRelationships2.ts, 49, 1))
221+
222+
field1: 5,
223+
>field1 : Symbol(field1, Decl(mappedTypeRelationships2.ts, 63, 36))
224+
225+
field2: "something",
226+
>field2 : Symbol(field2, Decl(mappedTypeRelationships2.ts, 64, 14))
227+
228+
special: 32,
229+
>special : Symbol(special, Decl(mappedTypeRelationships2.ts, 65, 24))
230+
231+
};
232+
233+
// ok
234+
const works3: Lookup<K> = {
235+
>works3 : Symbol(works3, Decl(mappedTypeRelationships2.ts, 70, 7))
236+
>Lookup : Symbol(Lookup, Decl(mappedTypeRelationships2.ts, 49, 1))
237+
>K : Symbol(K, Decl(mappedTypeRelationships2.ts, 54, 18))
238+
239+
special: undefined,
240+
>special : Symbol(special, Decl(mappedTypeRelationships2.ts, 70, 29))
241+
>undefined : Symbol(undefined)
242+
243+
field1: undefined,
244+
>field1 : Symbol(field1, Decl(mappedTypeRelationships2.ts, 71, 23))
245+
>undefined : Symbol(undefined)
246+
247+
field2: undefined,
248+
>field2 : Symbol(field2, Decl(mappedTypeRelationships2.ts, 72, 22))
249+
>undefined : Symbol(undefined)
250+
251+
};
252+
253+
// error
254+
const works4: Lookup<K> = {
255+
>works4 : Symbol(works4, Decl(mappedTypeRelationships2.ts, 77, 7))
256+
>Lookup : Symbol(Lookup, Decl(mappedTypeRelationships2.ts, 49, 1))
257+
>K : Symbol(K, Decl(mappedTypeRelationships2.ts, 54, 18))
258+
259+
field1: undefined,
260+
>field1 : Symbol(field1, Decl(mappedTypeRelationships2.ts, 77, 29))
261+
>undefined : Symbol(undefined)
262+
263+
field2: undefined,
264+
>field2 : Symbol(field2, Decl(mappedTypeRelationships2.ts, 78, 22))
265+
>undefined : Symbol(undefined)
266+
267+
special: 32,
268+
>special : Symbol(special, Decl(mappedTypeRelationships2.ts, 79, 22))
269+
270+
};
271+
}
272+
145273
export {};
146274

tests/baselines/reference/mappedTypeRelationships2.types

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,154 @@ type Test10<T extends AB> = Alias5<T, ABC>; // ok
9191
>Test10 : ABC
9292
> : ^^^
9393

94+
// part of https://github.com/microsoft/TypeScript/issues/62770
95+
96+
interface WithCommon {
97+
field1: number;
98+
>field1 : number
99+
> : ^^^^^^
100+
101+
field2: string;
102+
>field2 : string
103+
> : ^^^^^^
104+
}
105+
106+
interface WithSpecial extends WithCommon {
107+
special: number;
108+
>special : number
109+
> : ^^^^^^
110+
}
111+
112+
interface SpecialLookup {
113+
special: WithSpecial;
114+
>special : WithSpecial
115+
> : ^^^^^^^^^^^
116+
}
117+
118+
interface CommonLookup extends SpecialLookup {
119+
common: WithCommon;
120+
>common : WithCommon
121+
> : ^^^^^^^^^^
122+
}
123+
124+
type Lookup<Name extends keyof CommonLookup> = {
125+
>Lookup : Lookup<Name>
126+
> : ^^^^^^^^^^^^
127+
128+
[K in keyof CommonLookup[Name]]?: CommonLookup[Name][K];
129+
};
130+
function someName<K extends keyof SpecialLookup>(): void {
131+
>someName : <K extends keyof SpecialLookup>() => void
132+
> : ^ ^^^^^^^^^ ^^^^^^^
133+
134+
// ok
135+
const works1: Lookup<"special"> = {
136+
>works1 : Lookup<"special">
137+
> : ^^^^^^^^^^^^^^^^^
138+
>{ field1: 1, field2: "common", special: 203, } : { field1: number; field2: string; special: number; }
139+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140+
141+
field1: 1,
142+
>field1 : number
143+
> : ^^^^^^
144+
>1 : 1
145+
> : ^
146+
147+
field2: "common",
148+
>field2 : string
149+
> : ^^^^^^
150+
>"common" : "common"
151+
> : ^^^^^^^^
152+
153+
special: 203,
154+
>special : number
155+
> : ^^^^^^
156+
>203 : 203
157+
> : ^^^
158+
159+
};
160+
161+
// error
162+
const works2: Lookup<"common"> = {
163+
>works2 : Lookup<"common">
164+
> : ^^^^^^^^^^^^^^^^
165+
>{ field1: 5, field2: "something", special: 32, } : { field1: number; field2: string; special: number; }
166+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167+
168+
field1: 5,
169+
>field1 : number
170+
> : ^^^^^^
171+
>5 : 5
172+
> : ^
173+
174+
field2: "something",
175+
>field2 : string
176+
> : ^^^^^^
177+
>"something" : "something"
178+
> : ^^^^^^^^^^^
179+
180+
special: 32,
181+
>special : number
182+
> : ^^^^^^
183+
>32 : 32
184+
> : ^^
185+
186+
};
187+
188+
// ok
189+
const works3: Lookup<K> = {
190+
>works3 : Lookup<K>
191+
> : ^^^^^^^^^
192+
>{ special: undefined, field1: undefined, field2: undefined, } : { special: undefined; field1: undefined; field2: undefined; }
193+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194+
195+
special: undefined,
196+
>special : undefined
197+
> : ^^^^^^^^^
198+
>undefined : undefined
199+
> : ^^^^^^^^^
200+
201+
field1: undefined,
202+
>field1 : undefined
203+
> : ^^^^^^^^^
204+
>undefined : undefined
205+
> : ^^^^^^^^^
206+
207+
field2: undefined,
208+
>field2 : undefined
209+
> : ^^^^^^^^^
210+
>undefined : undefined
211+
> : ^^^^^^^^^
212+
213+
};
214+
215+
// error
216+
const works4: Lookup<K> = {
217+
>works4 : Lookup<K>
218+
> : ^^^^^^^^^
219+
>{ field1: undefined, field2: undefined, special: 32, } : { field1: undefined; field2: undefined; special: 32; }
220+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221+
222+
field1: undefined,
223+
>field1 : undefined
224+
> : ^^^^^^^^^
225+
>undefined : undefined
226+
> : ^^^^^^^^^
227+
228+
field2: undefined,
229+
>field2 : undefined
230+
> : ^^^^^^^^^
231+
>undefined : undefined
232+
> : ^^^^^^^^^
233+
234+
special: 32,
235+
>special : 32
236+
> : ^^
237+
>32 : 32
238+
> : ^^
239+
240+
};
241+
}
242+
94243
export {};
95244

0 commit comments

Comments
 (0)