diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 017669603a..1cc8846bbb 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -211,6 +211,12 @@ function f55(obj: T, key: K) { const b = "foo" in obj[key]; } +function f60(source: T, target: T) { + for (let k in source) { + target[k] = source[k]; + } +} + // Repros from #12011 class Base { @@ -383,6 +389,11 @@ function f55(obj, key) { } var b = "foo" in obj[key]; } +function f60(source, target) { + for (var k in source) { + target[k] = source[k]; + } +} // Repros from #12011 var Base = (function () { function Base() { @@ -518,6 +529,7 @@ declare function f53(obj: { }, k: K, s: string, n: number): void; declare function f54(obj: T, key: keyof T): void; declare function f55(obj: T, key: K): void; +declare function f60(source: T, target: T): void; declare class Base { get(prop: K): this[K]; set(prop: K, value: this[K]): void; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 8a2f1052d1..634dfe09da 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -735,84 +735,104 @@ function f55(obj: T, key: K) { >key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) } +function f60(source: T, target: T) { +>f60 : Symbol(f60, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) +>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) + + for (let k in source) { +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) + + target[k] = source[k]; +>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) + } +} + // Repros from #12011 class Base { ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) get(prop: K) { ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 215, 8)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8)) return this[prop]; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 215, 30)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30)) } set(prop: K, value: this[K]) { ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 218, 8)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) this[prop] = value; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 218, 30)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 218, 38)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38)) } } class Person extends Base { ->Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) parts: number; ->parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 223, 27)) +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 229, 27)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16)) super(); ->super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 210, 1)) +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) this.set("parts", parts); ->this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 217, 5)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 225, 16)) +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16)) } getParts() { ->getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 228, 5)) +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 234, 5)) return this.get("parts") ->this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 221, 1)) ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 214, 12)) +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) } } class OtherPerson { ->OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) parts: number; ->parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 234, 19)) +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 240, 19)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16)) setProperty(this, "parts", parts); >setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 236, 16)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16)) } getParts() { ->getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 238, 5)) +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 244, 5)) return getProperty(this, "parts") >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 232, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 4c09909c0f..916b82aaf4 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -854,6 +854,29 @@ function f55(obj: T, key: K) { >key : K } +function f60(source: T, target: T) { +>f60 : (source: T, target: T) => void +>T : T +>source : T +>T : T +>target : T +>T : T + + for (let k in source) { +>k : keyof T +>source : T + + target[k] = source[k]; +>target[k] = source[k] : T[keyof T] +>target[k] : T[keyof T] +>target : T +>k : keyof T +>source[k] : T[keyof T] +>source : T +>k : keyof T + } +} + // Repros from #12011 class Base { diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 690154cb7a..b0451b8d55 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -211,6 +211,12 @@ function f55(obj: T, key: K) { const b = "foo" in obj[key]; } +function f60(source: T, target: T) { + for (let k in source) { + target[k] = source[k]; + } +} + // Repros from #12011 class Base {