From 4019265fe1bf8d7a0ef27fd1727304daff26c428 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 3 Nov 2016 10:01:42 -0700 Subject: [PATCH] Update tests --- .../types/keyof/keyofAndIndexedAccess.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index b63386a68a3..1e874aaf80f 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -7,6 +7,10 @@ class Shape { visible: boolean; } +class TaggedShape extends Shape { + tag: string; +} + class Item { name: string; price: number; @@ -149,6 +153,17 @@ function f32(key: K) { return shape[key]; // Shape[K] } +function f33(shape: S, key: K) { + let name = getProperty(shape, "name"); + let prop = getProperty(shape, key); + return prop; +} + +function f34(ts: TaggedShape) { + let tag1 = f33(ts, "tag"); + let tag2 = getProperty(ts, "tag"); +} + class C { public x: string; protected y: string; @@ -164,4 +179,36 @@ function f40(c: C) { let x: X = c["x"]; let y: Y = c["y"]; let z: Z = c["z"]; +} + +// Repros from #12011 + +class Base { + get(prop: K) { + return this[prop]; + } + set(prop: K, value: this[K]) { + this[prop] = value; + } +} + +class Person extends Base { + parts: number; + constructor(parts: number) { + super(); + this.set("parts", parts); + } + getParts() { + return this.get("parts") + } +} + +class OtherPerson { + parts: number; + constructor(parts: number) { + setProperty(this, "parts", parts); + } + getParts() { + return getProperty(this, "parts") + } } \ No newline at end of file