Skip to content

Commit 075a3eb

Browse files
committed
Add new tests
1 parent 79bdc26 commit 075a3eb

File tree

3 files changed

+437
-0
lines changed

3 files changed

+437
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(12,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
2+
Type 'T' is not assignable to type 'U'.
3+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(17,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
4+
Type 'T' is not assignable to type 'U'.
5+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
6+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
7+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2536: Type 'K' cannot be used to index type 'T'.
8+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,12): error TS2536: Type 'K' cannot be used to index type 'T'.
9+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(31,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
10+
Type 'undefined' is not assignable to type 'T[keyof T]'.
11+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(36,5): error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'.
12+
Type 'undefined' is not assignable to type 'T[K]'.
13+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
14+
Type 'undefined' is not assignable to type 'T[keyof T]'.
15+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(42,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'.
16+
Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
17+
Type 'T' is not assignable to type 'U'.
18+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'.
19+
Type 'undefined' is not assignable to type 'T[K]'.
20+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(47,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'.
21+
Type 'T[K]' is not assignable to type 'U[K]'.
22+
Type 'T' is not assignable to type 'U'.
23+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(52,5): error TS2542: Index signature in type 'Readonly<T>' only permits reading.
24+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(57,5): error TS2542: Index signature in type 'Readonly<T>' only permits reading.
25+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(62,5): error TS2542: Index signature in type 'Readonly<U>' only permits reading.
26+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(67,5): error TS2542: Index signature in type 'Readonly<U>' only permits reading.
27+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(71,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
28+
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
29+
30+
31+
==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (18 errors) ====
32+
33+
function f1<T>(x: T, k: keyof T) {
34+
return x[k];
35+
}
36+
37+
function f2<T, K extends keyof T>(x: T, k: K) {
38+
return x[k];
39+
}
40+
41+
function f3<T, U extends T>(x: T, y: U, k: keyof T) {
42+
x[k] = y[k];
43+
y[k] = x[k]; // Error
44+
~~~~
45+
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
46+
!!! error TS2322: Type 'T' is not assignable to type 'U'.
47+
}
48+
49+
function f4<T, U extends T, K extends keyof T>(x: T, y: U, k: K) {
50+
x[k] = y[k];
51+
y[k] = x[k]; // Error
52+
~~~~
53+
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
54+
!!! error TS2322: Type 'T' is not assignable to type 'U'.
55+
}
56+
57+
function f5<T, U extends T>(x: T, y: U, k: keyof U) {
58+
x[k] = y[k]; // Error
59+
~~~~
60+
!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'.
61+
y[k] = x[k]; // Error
62+
~~~~
63+
!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'.
64+
}
65+
66+
function f6<T, U extends T, K extends keyof U>(x: T, y: U, k: K) {
67+
x[k] = y[k]; // Error
68+
~~~~
69+
!!! error TS2536: Type 'K' cannot be used to index type 'T'.
70+
y[k] = x[k]; // Error
71+
~~~~
72+
!!! error TS2536: Type 'K' cannot be used to index type 'T'.
73+
}
74+
75+
function f10<T>(x: T, y: Partial<T>, k: keyof T) {
76+
x[k] = y[k]; // Error
77+
~~~~
78+
!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
79+
!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'.
80+
y[k] = x[k];
81+
}
82+
83+
function f11<T, K extends keyof T>(x: T, y: Partial<T>, k: K) {
84+
x[k] = y[k]; // Error
85+
~~~~
86+
!!! error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'.
87+
!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'.
88+
y[k] = x[k];
89+
}
90+
91+
function f12<T, U extends T>(x: T, y: Partial<U>, k: keyof T) {
92+
x[k] = y[k]; // Error
93+
~~~~
94+
!!! error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
95+
!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'.
96+
y[k] = x[k]; // Error
97+
~~~~
98+
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'.
99+
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
100+
!!! error TS2322: Type 'T' is not assignable to type 'U'.
101+
}
102+
103+
function f13<T, U extends T, K extends keyof T>(x: T, y: Partial<U>, k: K) {
104+
x[k] = y[k]; // Error
105+
~~~~
106+
!!! error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'.
107+
!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'.
108+
y[k] = x[k]; // Error
109+
~~~~
110+
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'.
111+
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
112+
!!! error TS2322: Type 'T' is not assignable to type 'U'.
113+
}
114+
115+
function f20<T>(x: T, y: Readonly<T>, k: keyof T) {
116+
x[k] = y[k];
117+
y[k] = x[k]; // Error
118+
~~~~
119+
!!! error TS2542: Index signature in type 'Readonly<T>' only permits reading.
120+
}
121+
122+
function f21<T, K extends keyof T>(x: T, y: Readonly<T>, k: K) {
123+
x[k] = y[k];
124+
y[k] = x[k]; // Error
125+
~~~~
126+
!!! error TS2542: Index signature in type 'Readonly<T>' only permits reading.
127+
}
128+
129+
function f22<T, U extends T>(x: T, y: Readonly<U>, k: keyof T) {
130+
x[k] = y[k];
131+
y[k] = x[k]; // Error
132+
~~~~
133+
!!! error TS2542: Index signature in type 'Readonly<U>' only permits reading.
134+
}
135+
136+
function f23<T, U extends T, K extends keyof T>(x: T, y: Readonly<U>, k: K) {
137+
x[k] = y[k];
138+
y[k] = x[k]; // Error
139+
~~~~
140+
!!! error TS2542: Index signature in type 'Readonly<U>' only permits reading.
141+
}
142+
143+
function f30<T>(x: T, y: Partial<T>) {
144+
x = y; // Error
145+
~
146+
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
147+
y = x;
148+
}
149+
150+
function f31<T>(x: T, y: Partial<T>) {
151+
x = y; // Error
152+
~
153+
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
154+
y = x;
155+
}
156+
157+
function f40<T>(x: T, y: Readonly<T>) {
158+
x = y;
159+
y = x;
160+
}
161+
162+
function f41<T>(x: T, y: Readonly<T>) {
163+
x = y;
164+
y = x;
165+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
//// [mappedTypeRelationships.ts]
2+
3+
function f1<T>(x: T, k: keyof T) {
4+
return x[k];
5+
}
6+
7+
function f2<T, K extends keyof T>(x: T, k: K) {
8+
return x[k];
9+
}
10+
11+
function f3<T, U extends T>(x: T, y: U, k: keyof T) {
12+
x[k] = y[k];
13+
y[k] = x[k]; // Error
14+
}
15+
16+
function f4<T, U extends T, K extends keyof T>(x: T, y: U, k: K) {
17+
x[k] = y[k];
18+
y[k] = x[k]; // Error
19+
}
20+
21+
function f5<T, U extends T>(x: T, y: U, k: keyof U) {
22+
x[k] = y[k]; // Error
23+
y[k] = x[k]; // Error
24+
}
25+
26+
function f6<T, U extends T, K extends keyof U>(x: T, y: U, k: K) {
27+
x[k] = y[k]; // Error
28+
y[k] = x[k]; // Error
29+
}
30+
31+
function f10<T>(x: T, y: Partial<T>, k: keyof T) {
32+
x[k] = y[k]; // Error
33+
y[k] = x[k];
34+
}
35+
36+
function f11<T, K extends keyof T>(x: T, y: Partial<T>, k: K) {
37+
x[k] = y[k]; // Error
38+
y[k] = x[k];
39+
}
40+
41+
function f12<T, U extends T>(x: T, y: Partial<U>, k: keyof T) {
42+
x[k] = y[k]; // Error
43+
y[k] = x[k]; // Error
44+
}
45+
46+
function f13<T, U extends T, K extends keyof T>(x: T, y: Partial<U>, k: K) {
47+
x[k] = y[k]; // Error
48+
y[k] = x[k]; // Error
49+
}
50+
51+
function f20<T>(x: T, y: Readonly<T>, k: keyof T) {
52+
x[k] = y[k];
53+
y[k] = x[k]; // Error
54+
}
55+
56+
function f21<T, K extends keyof T>(x: T, y: Readonly<T>, k: K) {
57+
x[k] = y[k];
58+
y[k] = x[k]; // Error
59+
}
60+
61+
function f22<T, U extends T>(x: T, y: Readonly<U>, k: keyof T) {
62+
x[k] = y[k];
63+
y[k] = x[k]; // Error
64+
}
65+
66+
function f23<T, U extends T, K extends keyof T>(x: T, y: Readonly<U>, k: K) {
67+
x[k] = y[k];
68+
y[k] = x[k]; // Error
69+
}
70+
71+
function f30<T>(x: T, y: Partial<T>) {
72+
x = y; // Error
73+
y = x;
74+
}
75+
76+
function f31<T>(x: T, y: Partial<T>) {
77+
x = y; // Error
78+
y = x;
79+
}
80+
81+
function f40<T>(x: T, y: Readonly<T>) {
82+
x = y;
83+
y = x;
84+
}
85+
86+
function f41<T>(x: T, y: Readonly<T>) {
87+
x = y;
88+
y = x;
89+
}
90+
91+
//// [mappedTypeRelationships.js]
92+
function f1(x, k) {
93+
return x[k];
94+
}
95+
function f2(x, k) {
96+
return x[k];
97+
}
98+
function f3(x, y, k) {
99+
x[k] = y[k];
100+
y[k] = x[k]; // Error
101+
}
102+
function f4(x, y, k) {
103+
x[k] = y[k];
104+
y[k] = x[k]; // Error
105+
}
106+
function f5(x, y, k) {
107+
x[k] = y[k]; // Error
108+
y[k] = x[k]; // Error
109+
}
110+
function f6(x, y, k) {
111+
x[k] = y[k]; // Error
112+
y[k] = x[k]; // Error
113+
}
114+
function f10(x, y, k) {
115+
x[k] = y[k]; // Error
116+
y[k] = x[k];
117+
}
118+
function f11(x, y, k) {
119+
x[k] = y[k]; // Error
120+
y[k] = x[k];
121+
}
122+
function f12(x, y, k) {
123+
x[k] = y[k]; // Error
124+
y[k] = x[k]; // Error
125+
}
126+
function f13(x, y, k) {
127+
x[k] = y[k]; // Error
128+
y[k] = x[k]; // Error
129+
}
130+
function f20(x, y, k) {
131+
x[k] = y[k];
132+
y[k] = x[k]; // Error
133+
}
134+
function f21(x, y, k) {
135+
x[k] = y[k];
136+
y[k] = x[k]; // Error
137+
}
138+
function f22(x, y, k) {
139+
x[k] = y[k];
140+
y[k] = x[k]; // Error
141+
}
142+
function f23(x, y, k) {
143+
x[k] = y[k];
144+
y[k] = x[k]; // Error
145+
}
146+
function f30(x, y) {
147+
x = y; // Error
148+
y = x;
149+
}
150+
function f31(x, y) {
151+
x = y; // Error
152+
y = x;
153+
}
154+
function f40(x, y) {
155+
x = y;
156+
y = x;
157+
}
158+
function f41(x, y) {
159+
x = y;
160+
y = x;
161+
}
162+
163+
164+
//// [mappedTypeRelationships.d.ts]
165+
declare function f1<T>(x: T, k: keyof T): T[keyof T];
166+
declare function f2<T, K extends keyof T>(x: T, k: K): T[K];
167+
declare function f3<T, U extends T>(x: T, y: U, k: keyof T): void;
168+
declare function f4<T, U extends T, K extends keyof T>(x: T, y: U, k: K): void;
169+
declare function f5<T, U extends T>(x: T, y: U, k: keyof U): void;
170+
declare function f6<T, U extends T, K extends keyof U>(x: T, y: U, k: K): void;
171+
declare function f10<T>(x: T, y: Partial<T>, k: keyof T): void;
172+
declare function f11<T, K extends keyof T>(x: T, y: Partial<T>, k: K): void;
173+
declare function f12<T, U extends T>(x: T, y: Partial<U>, k: keyof T): void;
174+
declare function f13<T, U extends T, K extends keyof T>(x: T, y: Partial<U>, k: K): void;
175+
declare function f20<T>(x: T, y: Readonly<T>, k: keyof T): void;
176+
declare function f21<T, K extends keyof T>(x: T, y: Readonly<T>, k: K): void;
177+
declare function f22<T, U extends T>(x: T, y: Readonly<U>, k: keyof T): void;
178+
declare function f23<T, U extends T, K extends keyof T>(x: T, y: Readonly<U>, k: K): void;
179+
declare function f30<T>(x: T, y: Partial<T>): void;
180+
declare function f31<T>(x: T, y: Partial<T>): void;
181+
declare function f40<T>(x: T, y: Readonly<T>): void;
182+
declare function f41<T>(x: T, y: Readonly<T>): void;

0 commit comments

Comments
 (0)