Skip to content

Commit b662a8b

Browse files
committed
Add test case
1 parent dbc661f commit b662a8b

File tree

4 files changed

+97
-36
lines changed

4 files changed

+97
-36
lines changed

Diff for: tests/baselines/reference/keyofAndIndexedAccess.js

+12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ function f55<T, K extends keyof T>(obj: T, key: K) {
211211
const b = "foo" in obj[key];
212212
}
213213

214+
function f60<T>(source: T, target: T) {
215+
for (let k in source) {
216+
target[k] = source[k];
217+
}
218+
}
219+
214220
// Repros from #12011
215221

216222
class Base {
@@ -383,6 +389,11 @@ function f55(obj, key) {
383389
}
384390
var b = "foo" in obj[key];
385391
}
392+
function f60(source, target) {
393+
for (var k in source) {
394+
target[k] = source[k];
395+
}
396+
}
386397
// Repros from #12011
387398
var Base = (function () {
388399
function Base() {
@@ -518,6 +529,7 @@ declare function f53<T, K extends keyof T>(obj: {
518529
}, k: K, s: string, n: number): void;
519530
declare function f54<T>(obj: T, key: keyof T): void;
520531
declare function f55<T, K extends keyof T>(obj: T, key: K): void;
532+
declare function f60<T>(source: T, target: T): void;
521533
declare class Base {
522534
get<K extends keyof this>(prop: K): this[K];
523535
set<K extends keyof this>(prop: K, value: this[K]): void;

Diff for: tests/baselines/reference/keyofAndIndexedAccess.symbols

+56-36
Original file line numberDiff line numberDiff line change
@@ -735,84 +735,104 @@ function f55<T, K extends keyof T>(obj: T, key: K) {
735735
>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42))
736736
}
737737

738+
function f60<T>(source: T, target: T) {
739+
>f60 : Symbol(f60, Decl(keyofAndIndexedAccess.ts, 210, 1))
740+
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13))
741+
>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16))
742+
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13))
743+
>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26))
744+
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13))
745+
746+
for (let k in source) {
747+
>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12))
748+
>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16))
749+
750+
target[k] = source[k];
751+
>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26))
752+
>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12))
753+
>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16))
754+
>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12))
755+
}
756+
}
757+
738758
// Repros from #12011
739759

740760
class Base {
741-
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1))
761+
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1))
742762

743763
get<K extends keyof this>(prop: K) {
744-
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12))
745-
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8))
746-
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30))
747-
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8))
764+
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12))
765+
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8))
766+
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30))
767+
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8))
748768

749769
return this[prop];
750-
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1))
751-
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30))
770+
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1))
771+
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30))
752772
}
753773
set<K extends keyof this>(prop: K, value: this[K]) {
754-
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5))
755-
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8))
756-
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30))
757-
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8))
758-
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38))
759-
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8))
774+
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5))
775+
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8))
776+
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30))
777+
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8))
778+
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38))
779+
>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8))
760780

761781
this[prop] = value;
762-
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1))
763-
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30))
764-
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38))
782+
>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1))
783+
>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30))
784+
>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38))
765785
}
766786
}
767787

768788
class Person extends Base {
769-
>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1))
770-
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1))
789+
>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1))
790+
>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1))
771791

772792
parts: number;
773-
>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 223, 27))
793+
>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 229, 27))
774794

775795
constructor(parts: number) {
776-
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16))
796+
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16))
777797

778798
super();
779-
>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1))
799+
>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1))
780800

781801
this.set("parts", parts);
782-
>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5))
783-
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1))
784-
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5))
785-
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16))
802+
>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5))
803+
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1))
804+
>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5))
805+
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16))
786806
}
787807
getParts() {
788-
>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 228, 5))
808+
>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 234, 5))
789809

790810
return this.get("parts")
791-
>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12))
792-
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1))
793-
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12))
811+
>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12))
812+
>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1))
813+
>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12))
794814
}
795815
}
796816

797817
class OtherPerson {
798-
>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1))
818+
>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1))
799819

800820
parts: number;
801-
>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 234, 19))
821+
>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 240, 19))
802822

803823
constructor(parts: number) {
804-
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16))
824+
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16))
805825

806826
setProperty(this, "parts", parts);
807827
>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1))
808-
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1))
809-
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16))
828+
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1))
829+
>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16))
810830
}
811831
getParts() {
812-
>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 238, 5))
832+
>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 244, 5))
813833

814834
return getProperty(this, "parts")
815835
>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26))
816-
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1))
836+
>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1))
817837
}
818838
}

Diff for: tests/baselines/reference/keyofAndIndexedAccess.types

+23
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,29 @@ function f55<T, K extends keyof T>(obj: T, key: K) {
854854
>key : K
855855
}
856856

857+
function f60<T>(source: T, target: T) {
858+
>f60 : <T>(source: T, target: T) => void
859+
>T : T
860+
>source : T
861+
>T : T
862+
>target : T
863+
>T : T
864+
865+
for (let k in source) {
866+
>k : keyof T
867+
>source : T
868+
869+
target[k] = source[k];
870+
>target[k] = source[k] : T[keyof T]
871+
>target[k] : T[keyof T]
872+
>target : T
873+
>k : keyof T
874+
>source[k] : T[keyof T]
875+
>source : T
876+
>k : keyof T
877+
}
878+
}
879+
857880
// Repros from #12011
858881

859882
class Base {

Diff for: tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts

+6
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ function f55<T, K extends keyof T>(obj: T, key: K) {
211211
const b = "foo" in obj[key];
212212
}
213213

214+
function f60<T>(source: T, target: T) {
215+
for (let k in source) {
216+
target[k] = source[k];
217+
}
218+
}
219+
214220
// Repros from #12011
215221

216222
class Base {

0 commit comments

Comments
 (0)