forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenumBracketComputedPropertyName.types
More file actions
108 lines (95 loc) · 2.35 KB
/
enumBracketComputedPropertyName.types
File metadata and controls
108 lines (95 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//// [tests/cases/compiler/enumBracketComputedPropertyName.ts] ////
=== enumBracketComputedPropertyName.ts ===
// Enum members with non-identifier names should be usable as computed property
// keys in type literals, interfaces, and class members (GH#25083).
enum E {
>E : E
> : ^
"hello world" = "hw",
>"hello world" : (typeof E)["hello world"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>"hw" : "hw"
> : ^^^^
"3x14" = "pi",
>"3x14" : (typeof E)["3x14"]
> : ^^^^^^^^^^^^^^^^^^
>"pi" : "pi"
> : ^^^^
normal = "n",
>normal : E.normal
> : ^^^^^^^^
>"n" : "n"
> : ^^^
}
// type literal
type T1 = { [E["hello world"]]: string };
>T1 : T1
> : ^^
>[E["hello world"]] : string
> : ^^^^^^
>E["hello world"] : (typeof E)["hello world"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"hello world" : "hello world"
> : ^^^^^^^^^^^^^
type T2 = { [E["3x14"]]: boolean };
>T2 : T2
> : ^^
>[E["3x14"]] : boolean
> : ^^^^^^^
>E["3x14"] : (typeof E)["3x14"]
> : ^^^^^^^^^^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"3x14" : "3x14"
> : ^^^^^^
type T3 = { [E["normal"]]: number }; // bracket access to a normal-identifier member
>T3 : T3
> : ^^
>[E["normal"]] : number
> : ^^^^^^
>E["normal"] : E.normal
> : ^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"normal" : "normal"
> : ^^^^^^^^
// interface
interface I1 {
[E["hello world"]]: string;
>[E["hello world"]] : string
> : ^^^^^^
>E["hello world"] : (typeof E)["hello world"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"hello world" : "hello world"
> : ^^^^^^^^^^^^^
}
// access back through the computed key
declare const t1: T1;
>t1 : T1
> : ^^
const v1: string = t1[E["hello world"]];
>v1 : string
> : ^^^^^^
>t1[E["hello world"]] : string
> : ^^^^^^
>t1 : T1
> : ^^
>E["hello world"] : (typeof E)["hello world"]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>E : typeof E
> : ^^^^^^^^
>"hello world" : "hello world"
> : ^^^^^^^^^^^^^
const v2: string = t1["hw"]; // literal value
>v2 : string
> : ^^^^^^
>t1["hw"] : string
> : ^^^^^^
>t1 : T1
> : ^^
>"hw" : "hw"
> : ^^^^