Skip to content

Commit 69cd6c0

Browse files
committed
Accept new baselines
1 parent 3499462 commit 69cd6c0

7 files changed

+817
-734
lines changed

tests/baselines/reference/keyofAndIndexedAccess.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,16 @@ type S2 = {
300300
b: string;
301301
};
302302

303-
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) {
303+
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K]) {
304304
x1 = x2;
305305
x1 = x3;
306-
x1 = x4;
307306
x2 = x1;
308307
x2 = x3;
309-
x2 = x4;
310308
x3 = x1;
311309
x3 = x2;
312-
x3 = x4;
313-
x4 = x1;
314-
x4 = x2;
315-
x4 = x3;
316310
x1.length;
317311
x2.length;
318312
x3.length;
319-
x4.length;
320313
}
321314

322315
function f91<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]) {
@@ -886,23 +879,16 @@ var C1 = /** @class */ (function () {
886879
};
887880
return C1;
888881
}());
889-
function f90(x1, x2, x3, x4) {
882+
function f90(x1, x2, x3) {
890883
x1 = x2;
891884
x1 = x3;
892-
x1 = x4;
893885
x2 = x1;
894886
x2 = x3;
895-
x2 = x4;
896887
x3 = x1;
897888
x3 = x2;
898-
x3 = x4;
899-
x4 = x1;
900-
x4 = x2;
901-
x4 = x3;
902889
x1.length;
903890
x2.length;
904891
x3.length;
905-
x4.length;
906892
}
907893
function f91(x, y, z) {
908894
var a;
@@ -1240,7 +1226,7 @@ declare type S2 = {
12401226
a: string;
12411227
b: string;
12421228
};
1243-
declare function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]): void;
1229+
declare function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K]): void;
12441230
declare function f91<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]): void;
12451231
declare function f92<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]): void;
12461232
declare class Base {

tests/baselines/reference/keyofAndIndexedAccess.symbols

Lines changed: 646 additions & 678 deletions
Large diffs are not rendered by default.

tests/baselines/reference/keyofAndIndexedAccess.types

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,12 +1207,11 @@ type S2 = {
12071207

12081208
};
12091209

1210-
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) {
1211-
>f90 : <T extends S2, K extends "a" | "b">(x1: string, x2: T["a" | "b"], x3: S2[K], x4: T[K]) => void
1210+
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K]) {
1211+
>f90 : <T extends S2, K extends "a" | "b">(x1: string, x2: T["a" | "b"], x3: S2[K]) => void
12121212
>x1 : string
12131213
>x2 : T["a" | "b"]
12141214
>x3 : S2[K]
1215-
>x4 : T[K]
12161215

12171216
x1 = x2;
12181217
>x1 = x2 : T["a" | "b"]
@@ -1224,11 +1223,6 @@ function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2]
12241223
>x1 : string
12251224
>x3 : S2[K]
12261225

1227-
x1 = x4;
1228-
>x1 = x4 : T[K]
1229-
>x1 : string
1230-
>x4 : T[K]
1231-
12321226
x2 = x1;
12331227
>x2 = x1 : string
12341228
>x2 : T["a" | "b"]
@@ -1239,11 +1233,6 @@ function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2]
12391233
>x2 : T["a" | "b"]
12401234
>x3 : S2[K]
12411235

1242-
x2 = x4;
1243-
>x2 = x4 : T[K]
1244-
>x2 : T["a" | "b"]
1245-
>x4 : T[K]
1246-
12471236
x3 = x1;
12481237
>x3 = x1 : string
12491238
>x3 : S2[K]
@@ -1254,26 +1243,6 @@ function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2]
12541243
>x3 : S2[K]
12551244
>x2 : T["a" | "b"]
12561245

1257-
x3 = x4;
1258-
>x3 = x4 : T[K]
1259-
>x3 : S2[K]
1260-
>x4 : T[K]
1261-
1262-
x4 = x1;
1263-
>x4 = x1 : string
1264-
>x4 : T[K]
1265-
>x1 : string
1266-
1267-
x4 = x2;
1268-
>x4 = x2 : T["a" | "b"]
1269-
>x4 : T[K]
1270-
>x2 : T["a" | "b"]
1271-
1272-
x4 = x3;
1273-
>x4 = x3 : S2[K]
1274-
>x4 : T[K]
1275-
>x3 : S2[K]
1276-
12771246
x1.length;
12781247
>x1.length : number
12791248
>x1 : string
@@ -1287,11 +1256,6 @@ function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2]
12871256
x3.length;
12881257
>x3.length : number
12891258
>x3 : S2[K]
1290-
>length : number
1291-
1292-
x4.length;
1293-
>x4.length : number
1294-
>x4 : T[K]
12951259
>length : number
12961260
}
12971261

tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(117,5): error
6363
Type 'T' is not assignable to type 'U'.
6464
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(122,5): error TS2322: Type '42' is not assignable to type 'keyof T'.
6565
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(123,5): error TS2322: Type '"hello"' is not assignable to type 'keyof T'.
66+
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(140,5): error TS2322: Type '42' is not assignable to type 'T[K]'.
67+
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(141,5): error TS2322: Type '"hello"' is not assignable to type 'T[K]'.
68+
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error TS2322: Type 'number[]' is not assignable to type 'T[K]'.
6669

6770

68-
==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (38 errors) ====
71+
==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (41 errors) ====
6972
class Shape {
7073
name: string;
7174
width: number;
@@ -293,4 +296,29 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(123,5): error
293296
~
294297
!!! error TS2322: Type '"hello"' is not assignable to type 'keyof T'.
295298
}
299+
300+
// Repro from #27470
301+
302+
type UndefinedKeys<T extends Record<string, any>> = {
303+
[K in keyof T]: undefined extends T[K] ? K : never
304+
};
305+
306+
type MyType = {a: string, b: string | undefined}
307+
308+
type Result1 = UndefinedKeys<MyType>;
309+
310+
const a1: Result1['a'] = 'a'; // Error
311+
const b1: Result1['b'] = 'b';
312+
313+
function test1<T extends Record<string, any>, K extends keyof T>(t: T, k: K) {
314+
t[k] = 42; // Error
315+
~~~~
316+
!!! error TS2322: Type '42' is not assignable to type 'T[K]'.
317+
t[k] = "hello"; // Error
318+
~~~~
319+
!!! error TS2322: Type '"hello"' is not assignable to type 'T[K]'.
320+
t[k] = [10, 20]; // Error
321+
~~~~
322+
!!! error TS2322: Type 'number[]' is not assignable to type 'T[K]'.
323+
}
296324

tests/baselines/reference/keyofAndIndexedAccessErrors.js

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

127146

128147
//// [keyofAndIndexedAccessErrors.js]
@@ -189,3 +208,10 @@ function f4(k) {
189208
k = 42; // error
190209
k = "hello"; // error
191210
}
211+
var a1 = 'a'; // Error
212+
var b1 = 'b';
213+
function test1(t, k) {
214+
t[k] = 42; // Error
215+
t[k] = "hello"; // Error
216+
t[k] = [10, 20]; // Error
217+
}

tests/baselines/reference/keyofAndIndexedAccessErrors.symbols

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,61 @@ function f4<T extends { [K in keyof T]: string }>(k: keyof T) {
428428
>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 120, 50))
429429
}
430430

431+
// Repro from #27470
432+
433+
type UndefinedKeys<T extends Record<string, any>> = {
434+
>UndefinedKeys : Symbol(UndefinedKeys, Decl(keyofAndIndexedAccessErrors.ts, 123, 1))
435+
>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 127, 19))
436+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
437+
438+
[K in keyof T]: undefined extends T[K] ? K : never
439+
>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 128, 3))
440+
>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 127, 19))
441+
>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 127, 19))
442+
>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 128, 3))
443+
>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 128, 3))
444+
445+
};
446+
447+
type MyType = {a: string, b: string | undefined}
448+
>MyType : Symbol(MyType, Decl(keyofAndIndexedAccessErrors.ts, 129, 2))
449+
>a : Symbol(a, Decl(keyofAndIndexedAccessErrors.ts, 131, 15))
450+
>b : Symbol(b, Decl(keyofAndIndexedAccessErrors.ts, 131, 25))
451+
452+
type Result1 = UndefinedKeys<MyType>;
453+
>Result1 : Symbol(Result1, Decl(keyofAndIndexedAccessErrors.ts, 131, 48))
454+
>UndefinedKeys : Symbol(UndefinedKeys, Decl(keyofAndIndexedAccessErrors.ts, 123, 1))
455+
>MyType : Symbol(MyType, Decl(keyofAndIndexedAccessErrors.ts, 129, 2))
456+
457+
const a1: Result1['a'] = 'a'; // Error
458+
>a1 : Symbol(a1, Decl(keyofAndIndexedAccessErrors.ts, 135, 5))
459+
>Result1 : Symbol(Result1, Decl(keyofAndIndexedAccessErrors.ts, 131, 48))
460+
461+
const b1: Result1['b'] = 'b';
462+
>b1 : Symbol(b1, Decl(keyofAndIndexedAccessErrors.ts, 136, 5))
463+
>Result1 : Symbol(Result1, Decl(keyofAndIndexedAccessErrors.ts, 131, 48))
464+
465+
function test1<T extends Record<string, any>, K extends keyof T>(t: T, k: K) {
466+
>test1 : Symbol(test1, Decl(keyofAndIndexedAccessErrors.ts, 136, 29))
467+
>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 138, 15))
468+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
469+
>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 138, 45))
470+
>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 138, 15))
471+
>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 138, 65))
472+
>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 138, 15))
473+
>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 138, 70))
474+
>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 138, 45))
475+
476+
t[k] = 42; // Error
477+
>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 138, 65))
478+
>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 138, 70))
479+
480+
t[k] = "hello"; // Error
481+
>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 138, 65))
482+
>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 138, 70))
483+
484+
t[k] = [10, 20]; // Error
485+
>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 138, 65))
486+
>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 138, 70))
487+
}
488+

tests/baselines/reference/keyofAndIndexedAccessErrors.types

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,56 @@ function f4<T extends { [K in keyof T]: string }>(k: keyof T) {
412412
>"hello" : "hello"
413413
}
414414

415+
// Repro from #27470
416+
417+
type UndefinedKeys<T extends Record<string, any>> = {
418+
>UndefinedKeys : UndefinedKeys<T>
419+
420+
[K in keyof T]: undefined extends T[K] ? K : never
421+
};
422+
423+
type MyType = {a: string, b: string | undefined}
424+
>MyType : MyType
425+
>a : string
426+
>b : string
427+
428+
type Result1 = UndefinedKeys<MyType>;
429+
>Result1 : UndefinedKeys<MyType>
430+
431+
const a1: Result1['a'] = 'a'; // Error
432+
>a1 : "a"
433+
>'a' : "a"
434+
435+
const b1: Result1['b'] = 'b';
436+
>b1 : "b"
437+
>'b' : "b"
438+
439+
function test1<T extends Record<string, any>, K extends keyof T>(t: T, k: K) {
440+
>test1 : <T extends Record<string, any>, K extends keyof T>(t: T, k: K) => void
441+
>t : T
442+
>k : K
443+
444+
t[k] = 42; // Error
445+
>t[k] = 42 : 42
446+
>t[k] : T[K]
447+
>t : T
448+
>k : K
449+
>42 : 42
450+
451+
t[k] = "hello"; // Error
452+
>t[k] = "hello" : "hello"
453+
>t[k] : T[K]
454+
>t : T
455+
>k : K
456+
>"hello" : "hello"
457+
458+
t[k] = [10, 20]; // Error
459+
>t[k] = [10, 20] : number[]
460+
>t[k] : T[K]
461+
>t : T
462+
>k : K
463+
>[10, 20] : number[]
464+
>10 : 10
465+
>20 : 20
466+
}
467+

0 commit comments

Comments
 (0)