diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 0e630be9a43..1a0b90f3163 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -219,6 +219,36 @@ function f60(source: T, target: T) { } } +function f70(func: (k1: keyof (T | U), k2: keyof (T & U)) => void) { + func<{ a: any, b: any }, { a: any, c: any }>('a', 'a'); + func<{ a: any, b: any }, { a: any, c: any }>('a', 'b'); + func<{ a: any, b: any }, { a: any, c: any }>('a', 'c'); +} + +function f71(func: (x: T, y: U) => Partial) { + let x = func({ a: 1, b: "hello" }, { c: true }); + x.a; // number | undefined + x.b; // string | undefined + x.c; // boolean | undefined +} + +function f72(func: (x: T, y: U, k: K) => (T & U)[K]) { + let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number + let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string + let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +} + +function f73(func: (x: T, y: U, k: K) => (T & U)[K]) { + let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number + let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string + let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +} + +function f74(func: (x: T, y: U, k: K) => (T | U)[K]) { + let a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number + let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean +} + // Repros from #12011 class Base { @@ -291,7 +321,39 @@ var empty = one(() => {}) // inferred as {}, expected type Handlers = { [K in keyof T]: (t: T[K]) => void } declare function on(handlerHash: Handlers): T var hashOfEmpty1 = on({ test: () => {} }); // {} -var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean } +var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean } + +// Repro from #12624 + +interface Options1 { + data?: Data + computed?: Computed; +} + +declare class Component1 { + constructor(options: Options1); + get(key: K): (Data & Computed)[K]; +} + +let c1 = new Component1({ + data: { + hello: "" + } +}); + +c1.get("hello"); + +// Repro from #12625 + +interface Options2 { + data?: Data + computed?: Computed; +} + +declare class Component2 { + constructor(options: Options2); + get(key: K): (Data & Computed)[K]; +} //// [keyofAndIndexedAccess.js] var __extends = (this && this.__extends) || function (d, b) { @@ -438,6 +500,31 @@ function f60(source, target) { target[k] = source[k]; } } +function f70(func) { + func('a', 'a'); + func('a', 'b'); + func('a', 'c'); +} +function f71(func) { + var x = func({ a: 1, b: "hello" }, { c: true }); + x.a; // number | undefined + x.b; // string | undefined + x.c; // boolean | undefined +} +function f72(func) { + var a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number + var b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string + var c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +} +function f73(func) { + var a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number + var b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string + var c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +} +function f74(func) { + var a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number + var b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean +} // Repros from #12011 var Base = (function () { function Base() { @@ -496,6 +583,12 @@ var assignTo2 = function (object, key1, key2) { var empty = one(function () { }); // inferred as {}, expected var hashOfEmpty1 = on({ test: function () { } }); // {} var hashOfEmpty2 = on({ test: function (x) { } }); // { test: boolean } +var c1 = new Component1({ + data: { + hello: "" + } +}); +c1.get("hello"); //// [keyofAndIndexedAccess.d.ts] @@ -603,6 +696,11 @@ declare function f53(obj: { 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 function f70(func: (k1: keyof (T | U), k2: keyof (T & U)) => void): void; +declare function f71(func: (x: T, y: U) => Partial): void; +declare function f72(func: (x: T, y: U, k: K) => (T & U)[K]): void; +declare function f73(func: (x: T, y: U, k: K) => (T & U)[K]): void; +declare function f74(func: (x: T, y: U, k: K) => (T | U)[K]): void; declare class Base { get(prop: K): this[K]; set(prop: K, value: this[K]): void; @@ -640,3 +738,22 @@ declare var hashOfEmpty1: {}; declare var hashOfEmpty2: { test: boolean; }; +interface Options1 { + data?: Data; + computed?: Computed; +} +declare class Component1 { + constructor(options: Options1); + get(key: K): (Data & Computed)[K]; +} +declare let c1: Component1<{ + hello: string; +}, {}>; +interface Options2 { + data?: Data; + computed?: Computed; +} +declare class Component2 { + constructor(options: Options2); + get(key: K): (Data & Computed)[K]; +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index e67db316dad..bc9e53cdd7e 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -766,278 +766,557 @@ function f60(source: T, target: T) { } } +function f70(func: (k1: keyof (T | U), k2: keyof (T & U)) => void) { +>f70 : Symbol(f70, Decl(keyofAndIndexedAccess.ts, 218, 1)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 220, 13)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 220, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 220, 22)) +>k1 : Symbol(k1, Decl(keyofAndIndexedAccess.ts, 220, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 220, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 220, 22)) +>k2 : Symbol(k2, Decl(keyofAndIndexedAccess.ts, 220, 44)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 220, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 220, 22)) + + func<{ a: any, b: any }, { a: any, c: any }>('a', 'a'); +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 220, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 221, 10)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 221, 18)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 221, 30)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 221, 38)) + + func<{ a: any, b: any }, { a: any, c: any }>('a', 'b'); +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 220, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 222, 10)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 222, 18)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 222, 30)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 222, 38)) + + func<{ a: any, b: any }, { a: any, c: any }>('a', 'c'); +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 220, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 223, 10)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 223, 18)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 223, 30)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 223, 38)) +} + +function f71(func: (x: T, y: U) => Partial) { +>f71 : Symbol(f71, Decl(keyofAndIndexedAccess.ts, 224, 1)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 226, 13)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 226, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 226, 22)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 226, 20)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 226, 31)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 226, 22)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 226, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 226, 22)) + + let x = func({ a: 1, b: "hello" }, { c: true }); +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 227, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 226, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 227, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 227, 24)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 227, 40)) + + x.a; // number | undefined +>x.a : Symbol(a) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 227, 7)) +>a : Symbol(a) + + x.b; // string | undefined +>x.b : Symbol(b) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 227, 7)) +>b : Symbol(b) + + x.c; // boolean | undefined +>x.c : Symbol(c) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 227, 7)) +>c : Symbol(c) +} + +function f72(func: (x: T, y: U, k: K) => (T & U)[K]) { +>f72 : Symbol(f72, Decl(keyofAndIndexedAccess.ts, 231, 1)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 233, 13)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 233, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 233, 22)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 233, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 233, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 233, 22)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 233, 55)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 233, 20)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 233, 60)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 233, 22)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 233, 66)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 233, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 233, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 233, 22)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 233, 25)) + + let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 234, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 233, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 234, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 234, 24)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 234, 40)) + + let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 235, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 233, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 235, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 235, 24)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 235, 40)) + + let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 236, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 233, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 236, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 236, 24)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 236, 40)) +} + +function f73(func: (x: T, y: U, k: K) => (T & U)[K]) { +>f73 : Symbol(f73, Decl(keyofAndIndexedAccess.ts, 237, 1)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 239, 13)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 239, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 239, 22)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 239, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 239, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 239, 22)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 239, 51)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 239, 20)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 239, 56)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 239, 22)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 239, 62)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 239, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 239, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 239, 22)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 239, 25)) + + let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 240, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 239, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 240, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 240, 24)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 240, 40)) + + let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 241, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 239, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 241, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 241, 24)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 241, 40)) + + let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 242, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 239, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 242, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 242, 24)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 242, 40)) +} + +function f74(func: (x: T, y: U, k: K) => (T | U)[K]) { +>f74 : Symbol(f74, Decl(keyofAndIndexedAccess.ts, 243, 1)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 245, 13)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 245, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 245, 22)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 245, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 245, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 245, 22)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 245, 51)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 245, 20)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 245, 56)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 245, 22)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 245, 62)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 245, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 245, 20)) +>U : Symbol(U, Decl(keyofAndIndexedAccess.ts, 245, 22)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 245, 25)) + + let a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 246, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 245, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 246, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 246, 24)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 246, 40)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 246, 46)) + + let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 247, 7)) +>func : Symbol(func, Decl(keyofAndIndexedAccess.ts, 245, 13)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 247, 18)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 247, 24)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 247, 40)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 247, 46)) +} + // Repros from #12011 class Base { ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1)) get(prop: K) { ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 222, 12)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 223, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 223, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 223, 8)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 252, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 253, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 253, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 253, 8)) return this[prop]; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 223, 30)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 253, 30)) } set(prop: K, value: this[K]) { ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 225, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 226, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 226, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 226, 8)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 226, 38)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 226, 8)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 255, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 256, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 256, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 256, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 256, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 256, 8)) this[prop] = value; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 226, 30)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 226, 38)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 256, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 256, 38)) } } class Person extends Base { ->Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 229, 1)) ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 259, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1)) parts: number; ->parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 231, 27)) +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 261, 27)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 233, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 263, 16)) super(); ->super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 248, 1)) this.set("parts", parts); ->this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 225, 5)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 229, 1)) ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 225, 5)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 233, 16)) +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 255, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 259, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 255, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 263, 16)) } getParts() { ->getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 236, 5)) +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 266, 5)) return this.get("parts") ->this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 222, 12)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 229, 1)) ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 222, 12)) +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 252, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 259, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 252, 12)) } } class OtherPerson { ->OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 240, 1)) +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 270, 1)) parts: number; ->parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 242, 19)) +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 272, 19)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 244, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 274, 16)) setProperty(this, "parts", parts); >setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 240, 1)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 244, 16)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 270, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 274, 16)) } getParts() { ->getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 246, 5)) +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 276, 5)) return getProperty(this, "parts") >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 240, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 270, 1)) } } // Modified repro from #12544 function path(obj: T, key1: K1): T[K1]; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 254, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 254, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 254, 14)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 254, 37)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 254, 14)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 254, 44)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 254, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 254, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 254, 16)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 284, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 284, 37)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 284, 44)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 284, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 284, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 284, 16)) function path(obj: T, key1: K1, key2: K2): T[K1][K2]; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 255, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 255, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 255, 14)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 255, 36)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 255, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 255, 16)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 255, 61)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 255, 14)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 255, 68)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 255, 16)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 255, 78)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 255, 36)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 255, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 255, 16)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 255, 36)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 285, 36)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 285, 61)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 285, 68)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 285, 78)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 285, 36)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 285, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 285, 16)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 285, 36)) function path(obj: T, key1: K1, key2: K2, key3: K3): T[K1][K2][K3]; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 256, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 256, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 256, 14)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 256, 36)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 256, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 256, 16)) ->K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 256, 60)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 256, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 256, 16)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 256, 36)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 256, 89)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 256, 14)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 256, 96)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 256, 16)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 256, 106)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 256, 36)) ->key3 : Symbol(key3, Decl(keyofAndIndexedAccess.ts, 256, 116)) ->K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 256, 60)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 256, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 256, 16)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 256, 36)) ->K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 256, 60)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16)) +>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 286, 60)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 286, 89)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 286, 96)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 286, 106)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36)) +>key3 : Symbol(key3, Decl(keyofAndIndexedAccess.ts, 286, 116)) +>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 286, 60)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 286, 16)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 286, 36)) +>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 286, 60)) function path(obj: any, ...keys: (string | number)[]): any; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 257, 14)) ->keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 257, 23)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 287, 14)) +>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 287, 23)) function path(obj: any, ...keys: (string | number)[]): any { ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 258, 14)) ->keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 258, 23)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 288, 14)) +>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 288, 23)) let result = obj; ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 259, 7)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 258, 14)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 288, 14)) for (let k of keys) { ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 260, 12)) ->keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 258, 23)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 290, 12)) +>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 288, 23)) result = result[k]; ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 259, 7)) ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 259, 7)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 260, 12)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 290, 12)) } return result; ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 259, 7)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 289, 7)) } type Thing = { ->Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 264, 1)) +>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 294, 1)) a: { x: number, y: string }, ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 266, 14)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 267, 8)) ->y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 267, 19)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 296, 14)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 297, 8)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 297, 19)) b: boolean ->b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 267, 32)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 297, 32)) }; function f1(thing: Thing) { ->f1 : Symbol(f1, Decl(keyofAndIndexedAccess.ts, 269, 2)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 272, 12)) ->Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 264, 1)) +>f1 : Symbol(f1, Decl(keyofAndIndexedAccess.ts, 299, 2)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12)) +>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 294, 1)) let x1 = path(thing, 'a'); // { x: number, y: string } ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 273, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 272, 12)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 303, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12)) let x2 = path(thing, 'a', 'y'); // string ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 274, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 272, 12)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 304, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12)) let x3 = path(thing, 'b'); // boolean ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 275, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 272, 12)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 305, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12)) let x4 = path(thing, ...['a', 'x']); // any ->x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 276, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 250, 1), Decl(keyofAndIndexedAccess.ts, 254, 62), Decl(keyofAndIndexedAccess.ts, 255, 100), Decl(keyofAndIndexedAccess.ts, 256, 142), Decl(keyofAndIndexedAccess.ts, 257, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 272, 12)) +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 306, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 280, 1), Decl(keyofAndIndexedAccess.ts, 284, 62), Decl(keyofAndIndexedAccess.ts, 285, 100), Decl(keyofAndIndexedAccess.ts, 286, 142), Decl(keyofAndIndexedAccess.ts, 287, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 302, 12)) } // Repro from comment in #12114 const assignTo2 = (object: T, key1: K1, key2: K2) => ->assignTo2 : Symbol(assignTo2, Decl(keyofAndIndexedAccess.ts, 281, 5)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 281, 19)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 281, 21)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 281, 19)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 281, 41)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 281, 19)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 281, 21)) ->object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 281, 66)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 281, 19)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 281, 76)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 281, 21)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 281, 86)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 281, 41)) +>assignTo2 : Symbol(assignTo2, Decl(keyofAndIndexedAccess.ts, 311, 5)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 311, 41)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21)) +>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 311, 66)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 311, 76)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 311, 86)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 311, 41)) (value: T[K1][K2]) => object[key1][key2] = value; ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 282, 5)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 281, 19)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 281, 21)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 281, 41)) ->object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 281, 66)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 281, 76)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 281, 86)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 282, 5)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 312, 5)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 311, 19)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 311, 21)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 311, 41)) +>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 311, 66)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 311, 76)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 311, 86)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 312, 5)) // Modified repro from #12573 declare function one(handler: (t: T) => void): T ->one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 282, 53)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 21)) ->handler : Symbol(handler, Decl(keyofAndIndexedAccess.ts, 286, 24)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 286, 34)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 21)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 286, 21)) +>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 312, 53)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 316, 21)) +>handler : Symbol(handler, Decl(keyofAndIndexedAccess.ts, 316, 24)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 316, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 316, 21)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 316, 21)) var empty = one(() => {}) // inferred as {}, expected ->empty : Symbol(empty, Decl(keyofAndIndexedAccess.ts, 287, 3)) ->one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 282, 53)) +>empty : Symbol(empty, Decl(keyofAndIndexedAccess.ts, 317, 3)) +>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 312, 53)) type Handlers = { [K in keyof T]: (t: T[K]) => void } ->Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 287, 25)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 289, 14)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 289, 22)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 289, 14)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 289, 38)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 289, 14)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 289, 22)) +>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 317, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 319, 14)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 319, 22)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 319, 14)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 319, 38)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 319, 14)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 319, 22)) declare function on(handlerHash: Handlers): T ->on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 289, 56)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 290, 20)) ->handlerHash : Symbol(handlerHash, Decl(keyofAndIndexedAccess.ts, 290, 23)) ->Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 287, 25)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 290, 20)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 290, 20)) +>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 319, 56)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 320, 20)) +>handlerHash : Symbol(handlerHash, Decl(keyofAndIndexedAccess.ts, 320, 23)) +>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 317, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 320, 20)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 320, 20)) var hashOfEmpty1 = on({ test: () => {} }); // {} ->hashOfEmpty1 : Symbol(hashOfEmpty1, Decl(keyofAndIndexedAccess.ts, 291, 3)) ->on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 289, 56)) ->test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 291, 23)) +>hashOfEmpty1 : Symbol(hashOfEmpty1, Decl(keyofAndIndexedAccess.ts, 321, 3)) +>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 319, 56)) +>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 321, 23)) var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean } ->hashOfEmpty2 : Symbol(hashOfEmpty2, Decl(keyofAndIndexedAccess.ts, 292, 3)) ->on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 289, 56)) ->test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 292, 23)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 292, 31)) +>hashOfEmpty2 : Symbol(hashOfEmpty2, Decl(keyofAndIndexedAccess.ts, 322, 3)) +>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 319, 56)) +>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 322, 23)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 322, 31)) +// Repro from #12624 + +interface Options1 { +>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 322, 52)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 326, 19)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 326, 24)) + + data?: Data +>data : Symbol(Options1.data, Decl(keyofAndIndexedAccess.ts, 326, 36)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 326, 19)) + + computed?: Computed; +>computed : Symbol(Options1.computed, Decl(keyofAndIndexedAccess.ts, 327, 15)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 326, 24)) +} + +declare class Component1 { +>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 329, 1)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30)) + + constructor(options: Options1); +>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 332, 16)) +>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 322, 52)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30)) + + get(key: K): (Data & Computed)[K]; +>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 332, 51)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 333, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 333, 43)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 333, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 331, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 331, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 333, 8)) +} + +let c1 = new Component1({ +>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 336, 3)) +>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 329, 1)) + + data: { +>data : Symbol(data, Decl(keyofAndIndexedAccess.ts, 336, 25)) + + hello: "" +>hello : Symbol(hello, Decl(keyofAndIndexedAccess.ts, 337, 11)) + } +}); + +c1.get("hello"); +>c1.get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 332, 51)) +>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 336, 3)) +>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 332, 51)) + +// Repro from #12625 + +interface Options2 { +>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 342, 16)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 346, 19)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 346, 24)) + + data?: Data +>data : Symbol(Options2.data, Decl(keyofAndIndexedAccess.ts, 346, 36)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 346, 19)) + + computed?: Computed; +>computed : Symbol(Options2.computed, Decl(keyofAndIndexedAccess.ts, 347, 15)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 346, 24)) +} + +declare class Component2 { +>Component2 : Symbol(Component2, Decl(keyofAndIndexedAccess.ts, 349, 1)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30)) + + constructor(options: Options2); +>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 352, 16)) +>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 342, 16)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30)) + + get(key: K): (Data & Computed)[K]; +>get : Symbol(Component2.get, Decl(keyofAndIndexedAccess.ts, 352, 51)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 353, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 353, 47)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 353, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 351, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 351, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 353, 8)) +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 9e1e7d4b4d1..7cd4b434af6 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -780,8 +780,8 @@ function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) >n : number const x3 = obj[k]; ->x3 : boolean ->obj[k] : boolean +>x3 : { [x: string]: boolean; }[keyof T] +>obj[k] : { [x: string]: boolean; }[keyof T] >obj : { [x: string]: boolean; } >k : keyof T } @@ -888,6 +888,264 @@ function f60(source: T, target: T) { } } +function f70(func: (k1: keyof (T | U), k2: keyof (T & U)) => void) { +>f70 : (func: (k1: keyof (T | U), k2: keyof (T & U)) => void) => void +>func : (k1: keyof (T | U), k2: keyof (T & U)) => void +>T : T +>U : U +>k1 : keyof (T | U) +>T : T +>U : U +>k2 : keyof (T & U) +>T : T +>U : U + + func<{ a: any, b: any }, { a: any, c: any }>('a', 'a'); +>func<{ a: any, b: any }, { a: any, c: any }>('a', 'a') : void +>func : (k1: keyof (T | U), k2: keyof (T & U)) => void +>a : any +>b : any +>a : any +>c : any +>'a' : "a" +>'a' : "a" + + func<{ a: any, b: any }, { a: any, c: any }>('a', 'b'); +>func<{ a: any, b: any }, { a: any, c: any }>('a', 'b') : void +>func : (k1: keyof (T | U), k2: keyof (T & U)) => void +>a : any +>b : any +>a : any +>c : any +>'a' : "a" +>'b' : "b" + + func<{ a: any, b: any }, { a: any, c: any }>('a', 'c'); +>func<{ a: any, b: any }, { a: any, c: any }>('a', 'c') : void +>func : (k1: keyof (T | U), k2: keyof (T & U)) => void +>a : any +>b : any +>a : any +>c : any +>'a' : "a" +>'c' : "c" +} + +function f71(func: (x: T, y: U) => Partial) { +>f71 : (func: (x: T, y: U) => Partial) => void +>func : (x: T, y: U) => Partial +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>Partial : Partial +>T : T +>U : U + + let x = func({ a: 1, b: "hello" }, { c: true }); +>x : Partial<{ a: number; b: string; } & { c: boolean; }> +>func({ a: 1, b: "hello" }, { c: true }) : Partial<{ a: number; b: string; } & { c: boolean; }> +>func : (x: T, y: U) => Partial +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ c: true } : { c: true; } +>c : boolean +>true : true + + x.a; // number | undefined +>x.a : number | undefined +>x : Partial<{ a: number; b: string; } & { c: boolean; }> +>a : number | undefined + + x.b; // string | undefined +>x.b : string | undefined +>x : Partial<{ a: number; b: string; } & { c: boolean; }> +>b : string | undefined + + x.c; // boolean | undefined +>x.c : boolean | undefined +>x : Partial<{ a: number; b: string; } & { c: boolean; }> +>c : boolean | undefined +} + +function f72(func: (x: T, y: U, k: K) => (T & U)[K]) { +>f72 : (func: (x: T, y: U, k: K) => (T & U)[K]) => void +>func : (x: T, y: U, k: K) => (T & U)[K] +>T : T +>U : U +>K : K +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>k : K +>K : K +>T : T +>U : U +>K : K + + let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number +>a : number +>func({ a: 1, b: "hello" }, { c: true }, 'a') : number +>func : (x: T, y: U, k: K) => (T & U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ c: true } : { c: true; } +>c : boolean +>true : true +>'a' : "a" + + let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string +>b : string +>func({ a: 1, b: "hello" }, { c: true }, 'b') : string +>func : (x: T, y: U, k: K) => (T & U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ c: true } : { c: true; } +>c : boolean +>true : true +>'b' : "b" + + let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +>c : boolean +>func({ a: 1, b: "hello" }, { c: true }, 'c') : boolean +>func : (x: T, y: U, k: K) => (T & U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ c: true } : { c: true; } +>c : boolean +>true : true +>'c' : "c" +} + +function f73(func: (x: T, y: U, k: K) => (T & U)[K]) { +>f73 : (func: (x: T, y: U, k: K) => (T & U)[K]) => void +>func : (x: T, y: U, k: K) => (T & U)[K] +>T : T +>U : U +>K : K +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>k : K +>K : K +>T : T +>U : U +>K : K + + let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number +>a : number +>func({ a: 1, b: "hello" }, { c: true }, 'a') : number +>func : (x: T, y: U, k: K) => (T & U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ c: true } : { c: true; } +>c : boolean +>true : true +>'a' : "a" + + let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string +>b : string +>func({ a: 1, b: "hello" }, { c: true }, 'b') : string +>func : (x: T, y: U, k: K) => (T & U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ c: true } : { c: true; } +>c : boolean +>true : true +>'b' : "b" + + let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean +>c : boolean +>func({ a: 1, b: "hello" }, { c: true }, 'c') : boolean +>func : (x: T, y: U, k: K) => (T & U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ c: true } : { c: true; } +>c : boolean +>true : true +>'c' : "c" +} + +function f74(func: (x: T, y: U, k: K) => (T | U)[K]) { +>f74 : (func: (x: T, y: U, k: K) => (T | U)[K]) => void +>func : (x: T, y: U, k: K) => (T | U)[K] +>T : T +>U : U +>K : K +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>k : K +>K : K +>T : T +>U : U +>K : K + + let a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number +>a : number +>func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a') : number +>func : (x: T, y: U, k: K) => (T | U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ a: 2, b: true } : { a: number; b: true; } +>a : number +>2 : 2 +>b : boolean +>true : true +>'a' : "a" + + let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean +>b : string | boolean +>func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b') : string | boolean +>func : (x: T, y: U, k: K) => (T | U)[K] +>{ a: 1, b: "hello" } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>"hello" : "hello" +>{ a: 2, b: true } : { a: number; b: true; } +>a : number +>2 : 2 +>b : boolean +>true : true +>'b' : "b" +} + // Repros from #12011 class Base { @@ -1202,3 +1460,103 @@ var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean } >(x: boolean) => {} : (x: boolean) => void >x : boolean +// Repro from #12624 + +interface Options1 { +>Options1 : Options1 +>Data : Data +>Computed : Computed + + data?: Data +>data : Data | undefined +>Data : Data + + computed?: Computed; +>computed : Computed | undefined +>Computed : Computed +} + +declare class Component1 { +>Component1 : Component1 +>Data : Data +>Computed : Computed + + constructor(options: Options1); +>options : Options1 +>Options1 : Options1 +>Data : Data +>Computed : Computed + + get(key: K): (Data & Computed)[K]; +>get : (key: K) => (Data & Computed)[K] +>K : K +>Data : Data +>Computed : Computed +>key : K +>K : K +>Data : Data +>Computed : Computed +>K : K +} + +let c1 = new Component1({ +>c1 : Component1<{ hello: string; }, {}> +>new Component1({ data: { hello: "" }}) : Component1<{ hello: string; }, {}> +>Component1 : typeof Component1 +>{ data: { hello: "" }} : { data: { hello: string; }; } + + data: { +>data : { hello: string; } +>{ hello: "" } : { hello: string; } + + hello: "" +>hello : string +>"" : "" + } +}); + +c1.get("hello"); +>c1.get("hello") : string +>c1.get : (key: K) => ({ hello: string; } & {})[K] +>c1 : Component1<{ hello: string; }, {}> +>get : (key: K) => ({ hello: string; } & {})[K] +>"hello" : "hello" + +// Repro from #12625 + +interface Options2 { +>Options2 : Options2 +>Data : Data +>Computed : Computed + + data?: Data +>data : Data | undefined +>Data : Data + + computed?: Computed; +>computed : Computed | undefined +>Computed : Computed +} + +declare class Component2 { +>Component2 : Component2 +>Data : Data +>Computed : Computed + + constructor(options: Options2); +>options : Options2 +>Options2 : Options2 +>Data : Data +>Computed : Computed + + get(key: K): (Data & Computed)[K]; +>get : (key: K) => (Data & Computed)[K] +>K : K +>Data : Data +>Computed : Computed +>key : K +>K : K +>Data : Data +>Computed : Computed +>K : K +} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index 23b79c16627..1e88e2abc43 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -21,9 +21,14 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(64,33): error tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(66,24): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(67,24): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(72,5): error TS2536: Type 'keyof (T & U)' cannot be used to index type 'T | U'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(76,5): error TS2322: Type 'T | U' is not assignable to type 'T & U'. + Type 'T' is not assignable to type 'T & U'. + Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(77,5): error TS2322: Type 'keyof (T & U)' is not assignable to type 'keyof (T | U)'. -==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (21 errors) ==== +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (24 errors) ==== class Shape { name: string; width: number; @@ -135,4 +140,23 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(67,24): error ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'. !!! error TS2345: Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'. + } + + function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { + o1[k1]; + o1[k2]; // Error + ~~~~~~ +!!! error TS2536: Type 'keyof (T & U)' cannot be used to index type 'T | U'. + o2[k1]; + o2[k2]; + o1 = o2; + o2 = o1; // Error + ~~ +!!! error TS2322: Type 'T | U' is not assignable to type 'T & U'. +!!! error TS2322: Type 'T' is not assignable to type 'T & U'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. + k1 = k2; // Error + ~~ +!!! error TS2322: Type 'keyof (T & U)' is not assignable to type 'keyof (T | U)'. + k2 = k1; } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js index 145d8e3f148..556aca12971 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.js +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -66,6 +66,17 @@ function f10(shape: Shape) { setProperty(shape, "name", "rectangle"); setProperty(shape, "size", 10); // Error setProperty(shape, cond ? "name" : "size", 10); // Error +} + +function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { + o1[k1]; + o1[k2]; // Error + o2[k1]; + o2[k2]; + o1 = o2; + o2 = o1; // Error + k1 = k2; // Error + k2 = k1; } //// [keyofAndIndexedAccessErrors.js] @@ -88,3 +99,13 @@ function f10(shape) { setProperty(shape, "size", 10); // Error setProperty(shape, cond ? "name" : "size", 10); // Error } +function f20(k1, k2, o1, o2) { + o1[k1]; + o1[k2]; // Error + o2[k1]; + o2[k2]; + o1 = o2; + o2 = o1; // Error + k1 = k2; // Error + k2 = k1; +}