Skip to content

Commit 3499462

Browse files
committed
Add tests
1 parent 2801c97 commit 3499462

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,23 +302,16 @@ type S2 = {
302302
b: string;
303303
};
304304

305-
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) {
305+
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K]) {
306306
x1 = x2;
307307
x1 = x3;
308-
x1 = x4;
309308
x2 = x1;
310309
x2 = x3;
311-
x2 = x4;
312310
x3 = x1;
313311
x3 = x2;
314-
x3 = x4;
315-
x4 = x1;
316-
x4 = x2;
317-
x4 = x3;
318312
x1.length;
319313
x2.length;
320314
x3.length;
321-
x4.length;
322315
}
323316

324317
function f91<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]) {

tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,22 @@ function f4<T extends { [K in keyof T]: string }>(k: keyof T) {
122122
k = 42; // error
123123
k = "hello"; // error
124124
}
125+
126+
// Repro from #27470
127+
128+
type UndefinedKeys<T extends Record<string, any>> = {
129+
[K in keyof T]: undefined extends T[K] ? K : never
130+
};
131+
132+
type MyType = {a: string, b: string | undefined}
133+
134+
type Result1 = UndefinedKeys<MyType>;
135+
136+
const a1: Result1['a'] = 'a'; // Error
137+
const b1: Result1['b'] = 'b';
138+
139+
function test1<T extends Record<string, any>, K extends keyof T>(t: T, k: K) {
140+
t[k] = 42; // Error
141+
t[k] = "hello"; // Error
142+
t[k] = [10, 20]; // Error
143+
}

0 commit comments

Comments
 (0)