From 16103a9ca2ba1d23e6e781fb16da83950eb073b8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 30 Jan 2017 15:40:31 -0800 Subject: [PATCH 1/3] Fix isSymbolInScopeOfMappedTypeParameter to include mapped types --- src/compiler/checker.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2e0c66ce3f..780bda03b0a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6864,6 +6864,11 @@ namespace ts { } } break; + case SyntaxKind.MappedType: + if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode((node).typeParameter)))) { + return true; + } + break; case SyntaxKind.JSDocFunctionType: const func = node as JSDocFunctionType; for (const p of func.parameters) { From 34b4dbb26000d726600c4565ccb75cbc4eb53d06 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 30 Jan 2017 15:47:18 -0800 Subject: [PATCH 2/3] Add regression test --- .../conformance/types/keyof/keyofAndIndexedAccess.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 04c26fbe8f7..a8a5acd450f 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -517,3 +517,13 @@ class B extends A<{ x: number}> { p.x; } } + +// Repro from #13749 + +class Form { + private childFormFactories: {[K in keyof T]: (v: T[K]) => Form} + + public set(prop: K, value: T[K]) { + this.childFormFactories[prop](value) + } +} From ebba3d6ba672458aa9f98ceef665e153c570505c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 30 Jan 2017 15:47:24 -0800 Subject: [PATCH 3/3] Accept new baselines --- .../reference/keyofAndIndexedAccess.js | 23 +++++++++++ .../reference/keyofAndIndexedAccess.symbols | 36 ++++++++++++++++++ .../reference/keyofAndIndexedAccess.types | 38 +++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index e7df8bbd5a1..62b848e97df 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -516,6 +516,16 @@ class B extends A<{ x: number}> { p.x; } } + +// Repro from #13749 + +class Form { + private childFormFactories: {[K in keyof T]: (v: T[K]) => Form} + + public set(prop: K, value: T[K]) { + this.childFormFactories[prop](value) + } +} //// [keyofAndIndexedAccess.js] @@ -862,6 +872,15 @@ var B = (function (_super) { }; return B; }(A)); +// Repro from #13749 +var Form = (function () { + function Form() { + } + Form.prototype.set = function (prop, value) { + this.childFormFactories[prop](value); + }; + return Form; +}()); //// [keyofAndIndexedAccess.d.ts] @@ -1104,3 +1123,7 @@ declare class B extends A<{ }> { f(p: this["props"]): void; } +declare class Form { + private childFormFactories; + set(prop: K, value: T[K]): void; +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 01501cd719c..54fff19f428 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -1844,3 +1844,39 @@ class B extends A<{ x: number}> { } } +// Repro from #13749 + +class Form { +>Form : Symbol(Form, Decl(keyofAndIndexedAccess.ts, 516, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 520, 11)) + + private childFormFactories: {[K in keyof T]: (v: T[K]) => Form} +>childFormFactories : Symbol(Form.childFormFactories, Decl(keyofAndIndexedAccess.ts, 520, 15)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 521, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 520, 11)) +>v : Symbol(v, Decl(keyofAndIndexedAccess.ts, 521, 50)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 520, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 521, 34)) +>Form : Symbol(Form, Decl(keyofAndIndexedAccess.ts, 516, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 520, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 521, 34)) + + public set(prop: K, value: T[K]) { +>set : Symbol(Form.set, Decl(keyofAndIndexedAccess.ts, 521, 73)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 523, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 520, 11)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 523, 34)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 523, 15)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 523, 42)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 520, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 523, 15)) + + this.childFormFactories[prop](value) +>this.childFormFactories : Symbol(Form.childFormFactories, Decl(keyofAndIndexedAccess.ts, 520, 15)) +>this : Symbol(Form, Decl(keyofAndIndexedAccess.ts, 516, 1)) +>childFormFactories : Symbol(Form.childFormFactories, Decl(keyofAndIndexedAccess.ts, 520, 15)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 523, 34)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 523, 42)) + } +} + diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 21c9d645ce4..e987ee9043b 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -2166,3 +2166,41 @@ class B extends A<{ x: number}> { } } +// Repro from #13749 + +class Form { +>Form : Form +>T : T + + private childFormFactories: {[K in keyof T]: (v: T[K]) => Form} +>childFormFactories : { [K in keyof T]: (v: T[K]) => Form; } +>K : K +>T : T +>v : T[K] +>T : T +>K : K +>Form : Form +>T : T +>K : K + + public set(prop: K, value: T[K]) { +>set : (prop: K, value: T[K]) => void +>K : K +>T : T +>prop : K +>K : K +>value : T[K] +>T : T +>K : K + + this.childFormFactories[prop](value) +>this.childFormFactories[prop](value) : Form +>this.childFormFactories[prop] : (v: T[K]) => Form +>this.childFormFactories : { [K in keyof T]: (v: T[K]) => Form; } +>this : this +>childFormFactories : { [K in keyof T]: (v: T[K]) => Form; } +>prop : K +>value : T[K] + } +} +