File tree Expand file tree Collapse file tree 2 files changed +32
-30
lines changed
tests/cases/conformance/types/mapped Expand file tree Collapse file tree 2 files changed +32
-30
lines changed Original file line number Diff line number Diff line change 1
1
// @strictNullChecks : true
2
2
// @declaration : true
3
3
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
-
20
4
interface Shape {
21
5
name : string ;
22
6
width : number ;
@@ -33,6 +17,8 @@ interface Point {
33
17
y : number ;
34
18
}
35
19
20
+ // Constraint checking
21
+
36
22
type T00 = { [ P in P ] : string } ; // Error
37
23
type T01 = { [ P in Date ] : number } ; // Error
38
24
type T02 = Record < Date , number > ; // Error
@@ -59,4 +45,25 @@ function f3<T extends keyof Shape>(x: T) {
59
45
60
46
function f4 < T extends keyof Named > ( x : T ) {
61
47
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
62
69
}
Original file line number Diff line number Diff line change 1
1
// @strictNullChecks : true
2
2
// @declaration : true
3
3
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 } ;
18
13
}
19
14
20
15
type Proxy < T > = {
You can’t perform that action at this time.
0 commit comments