From 04a0f55e96989cb6b9c59b40b4d2d83aab2d506e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 15 Nov 2016 12:15:11 -0800 Subject: [PATCH] Revise tests --- .../types/mapped/mappedTypeErrors.ts | 39 +++++++++++-------- .../conformance/types/mapped/mappedTypes2.ts | 23 +++++------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts index fce80872185..c507bf64a6e 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts @@ -1,22 +1,6 @@ // @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; @@ -33,6 +17,8 @@ interface Point { y: number; } +// Constraint checking + type T00 = { [P in P]: string }; // Error type T01 = { [P in Date]: number }; // Error type T02 = Record; // Error @@ -59,4 +45,25 @@ function f3(x: T) { function f4(x: T) { let y: Pick; +} + +// Type identity checking + +function f10() { + type K = keyof T; + var x: { [P in keyof T]: T[P] }; + var x: { [Q in keyof T]: T[Q] }; + var x: { [R in K]: T[R] }; +} + +function f11() { + var x: { [P in keyof T]: T[P] }; + var x: { [P in keyof T]?: T[P] }; // Error + var x: { readonly [P in keyof T]: T[P] }; // Error + var x: { readonly [P in keyof T]?: T[P] }; // Error +} + +function f12() { + var x: { [P in keyof T]: T[P] }; + var x: { [P in keyof T]: T[P][] }; // Error } \ No newline at end of file diff --git a/tests/cases/conformance/types/mapped/mappedTypes2.ts b/tests/cases/conformance/types/mapped/mappedTypes2.ts index 84bffe2ea17..7f5841410e4 100644 --- a/tests/cases/conformance/types/mapped/mappedTypes2.ts +++ b/tests/cases/conformance/types/mapped/mappedTypes2.ts @@ -1,20 +1,15 @@ // @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; +function verifyLibTypes() { + var x1: Partial; + var x1: { [P in keyof T]?: T[P] }; + var x2: Readonly; + var x2: { readonly [P in keyof T]: T[P] }; + var x3: Pick; + var x3: { [P in K]: T[P] }; + var x4: Record; + var x4: { [P in K]: U }; } type Proxy = {