Skip to content

Commit f1da780

Browse files
committed
Add regression tests
1 parent 33e5684 commit f1da780

File tree

4 files changed

+612
-252
lines changed

4 files changed

+612
-252
lines changed

tests/baselines/reference/keyofAndIndexedAccess.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,30 @@ class C1 {
296296
}
297297
}
298298

299+
type S2 = {
300+
a: string;
301+
b: string;
302+
};
303+
304+
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) {
305+
x1 = x2;
306+
x1 = x3;
307+
x1 = x4;
308+
x2 = x1;
309+
x2 = x3;
310+
x2 = x4;
311+
x3 = x1;
312+
x3 = x2;
313+
x3 = x4;
314+
x4 = x1;
315+
x4 = x2;
316+
x4 = x3;
317+
x1.length;
318+
x2.length;
319+
x3.length;
320+
x4.length;
321+
}
322+
299323
// Repros from #12011
300324

301325
class Base {
@@ -429,7 +453,17 @@ type SomeMethodDescriptor = {
429453
returnValue: string[];
430454
}
431455

432-
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
456+
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
457+
458+
// Repro from #13073
459+
460+
type KeyTypes = "a" | "b"
461+
let MyThingy: { [key in KeyTypes]: string[] };
462+
463+
function addToMyThingy<S extends KeyTypes>(key: S) {
464+
MyThingy[key].push("a");
465+
}
466+
433467

434468
//// [keyofAndIndexedAccess.js]
435469
var __extends = (this && this.__extends) || function (d, b) {
@@ -644,6 +678,24 @@ var C1 = (function () {
644678
};
645679
return C1;
646680
}());
681+
function f90(x1, x2, x3, x4) {
682+
x1 = x2;
683+
x1 = x3;
684+
x1 = x4;
685+
x2 = x1;
686+
x2 = x3;
687+
x2 = x4;
688+
x3 = x1;
689+
x3 = x2;
690+
x3 = x4;
691+
x4 = x1;
692+
x4 = x2;
693+
x4 = x3;
694+
x1.length;
695+
x2.length;
696+
x3.length;
697+
x4.length;
698+
}
647699
// Repros from #12011
648700
var Base = (function () {
649701
function Base() {
@@ -713,6 +765,10 @@ function f(p) {
713765
a[p].add; // any
714766
}
715767
var result = dispatchMethod("someMethod", ["hello", 35]);
768+
var MyThingy;
769+
function addToMyThingy(key) {
770+
MyThingy[key].push("a");
771+
}
716772

717773

718774
//// [keyofAndIndexedAccess.d.ts]
@@ -848,6 +904,11 @@ declare class C1 {
848904
set<K extends keyof this>(key: K, value: this[K]): void;
849905
foo(): void;
850906
}
907+
declare type S2 = {
908+
a: string;
909+
b: string;
910+
};
911+
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;
851912
declare class Base {
852913
get<K extends keyof this>(prop: K): this[K];
853914
set<K extends keyof this>(prop: K, value: this[K]): void;
@@ -920,3 +981,8 @@ declare type SomeMethodDescriptor = {
920981
returnValue: string[];
921982
};
922983
declare let result: string[];
984+
declare type KeyTypes = "a" | "b";
985+
declare let MyThingy: {
986+
[key in KeyTypes]: string[];
987+
};
988+
declare function addToMyThingy<S extends KeyTypes>(key: S): void;

0 commit comments

Comments
 (0)