From ca3f79783277beae5b06954cc7bec9463cc6789c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 11 Nov 2016 11:00:09 -0800 Subject: [PATCH] More tests --- .../types/mapped/mappedTypeErrors.ts | 62 +++++++++++++++++++ .../conformance/types/mapped/mappedTypes1.ts | 9 +++ 2 files changed, 71 insertions(+) create mode 100644 tests/cases/conformance/types/mapped/mappedTypeErrors.ts diff --git a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts new file mode 100644 index 00000000000..4017951f7c2 --- /dev/null +++ b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts @@ -0,0 +1,62 @@ +// @strictNullChecks: true +// @declaration: true + +type Partial = { + [P in keyof T]?: T[P]; +}; + +type Readonly = { + readonly [P in keyof T]: T[P]; +}; + +type Pick = { + [P in K]: T[P]; +} + +type Record = { + [_ in K]: T; +} + +interface Shape { + name: string; + width: number; + height: number; + visible: boolean; +} + +interface Named { + name: string; +} + +interface Point { + x: number; + y: number; +} + +type T00 = { [P in P]: string }; // Error +type T01 = { [P in Date]: number }; // Error +type T02 = Record; // Error + +type T10 = Pick; +type T11 = Pick; // Error +type T12 = Pick; // Error +type T13 = Pick; +type T14 = Pick; // Error +type T15 = Pick; +type T16 = Pick; + +function f1(x: T) { + let y: Pick; // Error +} + +function f2(x: T) { + let y: Pick; // Error +} + +function f3(x: T) { + let y: Pick; +} + +function f4(x: T) { + let y: Pick; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/mapped/mappedTypes1.ts b/tests/cases/conformance/types/mapped/mappedTypes1.ts index f57a14a2e10..bfc68aaa59d 100644 --- a/tests/cases/conformance/types/mapped/mappedTypes1.ts +++ b/tests/cases/conformance/types/mapped/mappedTypes1.ts @@ -26,6 +26,15 @@ type T36 = { [P in keyof void]: void }; type T37 = { [P in keyof symbol]: void }; type T38 = { [P in keyof never]: void }; +type T40 = { [P in string]: void }; +type T41 = { [P in number]: void }; +type T42 = { [P in string | number]: void }; +type T43 = { [P in "a" | "b" | 0 | 1]: void }; +type T44 = { [P in "a" | "b" | "0" | "1"]: void }; +type T45 = { [P in "a" | "b" | "0" | "1" | 0 | 1]: void }; +type T46 = { [P in number | "a" | "b" | 0 | 1]: void }; +type T47 = { [P in string | number | "a" | "b" | 0 | 1]: void }; + declare function f1(): { [P in keyof T1]: void }; declare function f2(): { [P in keyof T1]: void }; declare function f3(): { [P in keyof T1]: void };