From 6cd7454a9b7e3db223295c18d51a668c4eaddc4f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 14 Dec 2016 14:59:10 -0800 Subject: [PATCH] Add tests --- .../types/mapped/mappedTypeErrors.ts | 6 +++++ .../types/mapped/mappedTypeModifiers.ts | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts index 4be6b6b098..458dbe9caa 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts @@ -125,3 +125,9 @@ c.setState({ }); c.setState(foo); c.setState({ a: undefined }); // Error c.setState({ c: true }); // Error + +type T2 = { a?: number, [key: string]: any }; + +let x1: T2 = { a: 'no' }; // Error +let x2: Partial = { a: 'no' }; // Error +let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error \ No newline at end of file diff --git a/tests/cases/conformance/types/mapped/mappedTypeModifiers.ts b/tests/cases/conformance/types/mapped/mappedTypeModifiers.ts index 1fe6872965..a111d186d1 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeModifiers.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeModifiers.ts @@ -1,4 +1,5 @@ // @strictNullChecks: true +// @noimplicitany: true type T = { a: number, b: string }; type TP = { a?: number, b?: string }; @@ -74,4 +75,26 @@ var b04: Readonly; var b04: Partial>; var b04: Readonly>; var b04: { [P in keyof BPR]: BPR[P] } -var b04: Pick; \ No newline at end of file +var b04: Pick; + +type Foo = { prop: number, [x: string]: number }; + +function f1(x: Partial) { + x.prop; // ok + (x["other"] || 0).toFixed(); +} + +function f2(x: Readonly) { + x.prop; // ok + x["other"].toFixed(); +} + +function f3(x: Boxified) { + x.prop; // ok + x["other"].x.toFixed(); +} + +function f4(x: { [P in keyof Foo]: Foo[P] }) { + x.prop; // ok + x["other"].toFixed(); +}