File: enumBasics.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (232 lines) | stat: -rw-r--r-- 3,423 bytes parent folder | download | duplicates (4)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
=== tests/cases/conformance/enums/enumBasics.ts ===
// Enum without initializers have first member = 0 and successive members = N + 1
enum E1 {
>E1 : E1

    A,
>A : E1.A

    B,
>B : E1.B

    C
>C : E1.C
}

// Enum type is a subtype of Number
var x: number = E1.A;
>x : number
>E1.A : E1.A
>E1 : typeof E1
>A : E1.A

// Enum object type is anonymous with properties of the enum type and numeric indexer
var e = E1;
>e : typeof E1
>E1 : typeof E1

var e: {
>e : typeof E1

    readonly A: E1.A;
>A : E1.A
>E1 : any

    readonly B: E1.B;
>B : E1.B
>E1 : any

    readonly C: E1.C;
>C : E1.C
>E1 : any

    readonly [n: number]: string;
>n : number

};
var e: typeof E1;
>e : typeof E1
>E1 : typeof E1

// Reverse mapping of enum returns string name of property 
var s = E1[e.A];
>s : string
>E1[e.A] : string
>E1 : typeof E1
>e.A : E1.A
>e : typeof E1
>A : E1.A

var s: string;
>s : string


// Enum with only constant members
enum E2 {
>E2 : E2

    A = 1, B = 2, C = 3
>A : E2.A
>1 : 1
>B : E2.B
>2 : 2
>C : E2.C
>3 : 3
}

// Enum with only computed members
enum E3 {
>E3 : E3

    X = 'foo'.length, Y = 4 + 3, Z = +'foo'
>X : E3
>'foo'.length : number
>'foo' : "foo"
>length : number
>Y : E3
>4 + 3 : number
>4 : 4
>3 : 3
>Z : E3
>+'foo' : number
>'foo' : "foo"
}

// Enum with constant members followed by computed members
enum E4 {
>E4 : E4

    X = 0, Y, Z = 'foo'.length
>X : E4
>0 : 0
>Y : E4
>Z : E4
>'foo'.length : number
>'foo' : "foo"
>length : number
}

// Enum with > 2 constant members with no initializer for first member, non zero initializer for second element
enum E5 {
>E5 : E5

    A,
>A : E5.A

    B = 3,
>B : E5.B
>3 : 3

    C // 4
>C : E5.C
}

enum E6 {
>E6 : E6

    A,
>A : E6.A

    B = 0,
>B : E6.A
>0 : 0

    C // 1
>C : E6.C
}

// Enum with computed member initializer of type 'any'
enum E7 {
>E7 : E7

    A = 'foo'['foo']
>A : E7
>'foo'['foo'] : error
>'foo' : "foo"
>'foo' : "foo"
}

// Enum with computed member initializer of type number
enum E8 {
>E8 : E8

    B = 'foo'['foo']
>B : E8
>'foo'['foo'] : error
>'foo' : "foo"
>'foo' : "foo"
}

//Enum with computed member intializer of same enum type
enum E9 {
>E9 : E9

    A,
>A : E9.A

    B = A
>B : E9.A
>A : E9
}

// (refer to .js to validate)
// Enum constant members are propagated
var doNotPropagate = [
>doNotPropagate : (E3 | E4 | E7 | E8)[]
>[    E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : (E3 | E4 | E7 | E8)[]

    E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z
>E8.B : E8
>E8 : typeof E8
>B : E8
>E7.A : E7
>E7 : typeof E7
>A : E7
>E4.Z : E4
>E4 : typeof E4
>Z : E4
>E3.X : E3
>E3 : typeof E3
>X : E3
>E3.Y : E3
>E3 : typeof E3
>Y : E3
>E3.Z : E3
>E3 : typeof E3
>Z : E3

];
// Enum computed members are not propagated
var doPropagate = [
>doPropagate : (E9 | E6 | E5)[]
>[    E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : (E9 | E6 | E5)[]

    E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C
>E9.A : E9
>E9 : typeof E9
>A : E9
>E9.B : E9
>E9 : typeof E9
>B : E9
>E6.B : E6.A
>E6 : typeof E6
>B : E6.A
>E6.C : E6.C
>E6 : typeof E6
>C : E6.C
>E6.A : E6.A
>E6 : typeof E6
>A : E6.A
>E5.A : E5.A
>E5 : typeof E5
>A : E5.A
>E5.B : E5.B
>E5 : typeof E5
>B : E5.B
>E5.C : E5.C
>E5 : typeof E5
>C : E5.C

];