Skip to content

Commit 04a0f55

Browse files
committed
Revise tests
1 parent d32196f commit 04a0f55

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

tests/cases/conformance/types/mapped/mappedTypeErrors.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
// @strictNullChecks: true
22
// @declaration: true
33

4-
type Partial<T> = {
5-
[P in keyof T]?: T[P];
6-
};
7-
8-
type Readonly<T> = {
9-
readonly [P in keyof T]: T[P];
10-
};
11-
12-
type Pick<T, K extends keyof T> = {
13-
[P in K]: T[P];
14-
}
15-
16-
type Record<K extends string | number, T> = {
17-
[_ in K]: T;
18-
}
19-
204
interface Shape {
215
name: string;
226
width: number;
@@ -33,6 +17,8 @@ interface Point {
3317
y: number;
3418
}
3519

20+
// Constraint checking
21+
3622
type T00 = { [P in P]: string }; // Error
3723
type T01 = { [P in Date]: number }; // Error
3824
type T02 = Record<Date, number>; // Error
@@ -59,4 +45,25 @@ function f3<T extends keyof Shape>(x: T) {
5945

6046
function f4<T extends keyof Named>(x: T) {
6147
let y: Pick<Shape, T>;
48+
}
49+
50+
// Type identity checking
51+
52+
function f10<T>() {
53+
type K = keyof T;
54+
var x: { [P in keyof T]: T[P] };
55+
var x: { [Q in keyof T]: T[Q] };
56+
var x: { [R in K]: T[R] };
57+
}
58+
59+
function f11<T>() {
60+
var x: { [P in keyof T]: T[P] };
61+
var x: { [P in keyof T]?: T[P] }; // Error
62+
var x: { readonly [P in keyof T]: T[P] }; // Error
63+
var x: { readonly [P in keyof T]?: T[P] }; // Error
64+
}
65+
66+
function f12<T>() {
67+
var x: { [P in keyof T]: T[P] };
68+
var x: { [P in keyof T]: T[P][] }; // Error
6269
}

tests/cases/conformance/types/mapped/mappedTypes2.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
// @strictNullChecks: true
22
// @declaration: true
33

4-
type Partial<T> = {
5-
[P in keyof T]?: T[P];
6-
};
7-
8-
type Readonly<T> = {
9-
readonly [P in keyof T]: T[P];
10-
};
11-
12-
type Pick<T, K extends keyof T> = {
13-
[P in K]: T[P];
14-
}
15-
16-
type Record<K extends string | number, T> = {
17-
[_ in K]: T;
4+
function verifyLibTypes<T, K extends keyof T, U>() {
5+
var x1: Partial<T>;
6+
var x1: { [P in keyof T]?: T[P] };
7+
var x2: Readonly<T>;
8+
var x2: { readonly [P in keyof T]: T[P] };
9+
var x3: Pick<T, K>;
10+
var x3: { [P in K]: T[P] };
11+
var x4: Record<K, U>;
12+
var x4: { [P in K]: U };
1813
}
1914

2015
type Proxy<T> = {

0 commit comments

Comments
 (0)