Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6548bcf

Browse filesBrowse files
committed
Add new tests
1 parent 21d8e9a commit 6548bcf
Copy full SHA for 6548bcf

15 files changed

+3,289Lines changed: 3289 additions & 0 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+308Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
//// [enumClassification.ts]
2+
// An enum type where each member has no initializer or an initializer that specififes
3+
// a numeric literal, a string literal, or a single identifier naming another member in
4+
// the enum type is classified as a literal enum type. An enum type that doesn't adhere
5+
// to this pattern is classified as a numeric enum type.
6+
7+
// Examples of literal enum types
8+
9+
enum E01 {
10+
A
11+
}
12+
13+
enum E02 {
14+
A = 123
15+
}
16+
17+
enum E03 {
18+
A = "hello"
19+
}
20+
21+
enum E04 {
22+
A,
23+
B,
24+
C
25+
}
26+
27+
enum E05 {
28+
A,
29+
B = 10,
30+
C
31+
}
32+
33+
enum E06 {
34+
A = "one",
35+
B = "two",
36+
C = "three"
37+
}
38+
39+
enum E07 {
40+
A,
41+
B,
42+
C = "hi",
43+
D = 10,
44+
E,
45+
F = "bye"
46+
}
47+
48+
enum E08 {
49+
A = 10,
50+
B = "hello",
51+
C = A,
52+
D = B,
53+
E = C,
54+
}
55+
56+
// Examples of numeric enum types with only constant members
57+
58+
enum E10 {}
59+
60+
enum E11 {
61+
A = +0,
62+
B,
63+
C
64+
}
65+
66+
enum E12 {
67+
A = 1 << 0,
68+
B = 1 << 1,
69+
C = 1 << 2
70+
}
71+
72+
// Examples of numeric enum types with constant and computed members
73+
74+
enum E20 {
75+
A = "foo".length,
76+
B = A + 1,
77+
C = +"123",
78+
D = Math.sin(1)
79+
}
80+
81+
82+
//// [enumClassification.js]
83+
// An enum type where each member has no initializer or an initializer that specififes
84+
// a numeric literal, a string literal, or a single identifier naming another member in
85+
// the enum type is classified as a literal enum type. An enum type that doesn't adhere
86+
// to this pattern is classified as a numeric enum type.
87+
// Examples of literal enum types
88+
var E01;
89+
(function (E01) {
90+
E01[E01["A"] = 0] = "A";
91+
})(E01 || (E01 = {}));
92+
var E02;
93+
(function (E02) {
94+
E02[E02["A"] = 123] = "A";
95+
})(E02 || (E02 = {}));
96+
var E03;
97+
(function (E03) {
98+
E03["A"] = "hello";
99+
})(E03 || (E03 = {}));
100+
var E04;
101+
(function (E04) {
102+
E04[E04["A"] = 0] = "A";
103+
E04[E04["B"] = 1] = "B";
104+
E04[E04["C"] = 2] = "C";
105+
})(E04 || (E04 = {}));
106+
var E05;
107+
(function (E05) {
108+
E05[E05["A"] = 0] = "A";
109+
E05[E05["B"] = 10] = "B";
110+
E05[E05["C"] = 11] = "C";
111+
})(E05 || (E05 = {}));
112+
var E06;
113+
(function (E06) {
114+
E06["A"] = "one";
115+
E06["B"] = "two";
116+
E06["C"] = "three";
117+
})(E06 || (E06 = {}));
118+
var E07;
119+
(function (E07) {
120+
E07[E07["A"] = 0] = "A";
121+
E07[E07["B"] = 1] = "B";
122+
E07["C"] = "hi";
123+
E07[E07["D"] = 10] = "D";
124+
E07[E07["E"] = 11] = "E";
125+
E07["F"] = "bye";
126+
})(E07 || (E07 = {}));
127+
var E08;
128+
(function (E08) {
129+
E08[E08["A"] = 10] = "A";
130+
E08["B"] = "hello";
131+
E08[E08["C"] = 10] = "C";
132+
E08["D"] = "hello";
133+
E08[E08["E"] = 10] = "E";
134+
})(E08 || (E08 = {}));
135+
// Examples of numeric enum types with only constant members
136+
var E10;
137+
(function (E10) {
138+
})(E10 || (E10 = {}));
139+
var E11;
140+
(function (E11) {
141+
E11[E11["A"] = 0] = "A";
142+
E11[E11["B"] = 1] = "B";
143+
E11[E11["C"] = 2] = "C";
144+
})(E11 || (E11 = {}));
145+
var E12;
146+
(function (E12) {
147+
E12[E12["A"] = 1] = "A";
148+
E12[E12["B"] = 2] = "B";
149+
E12[E12["C"] = 4] = "C";
150+
})(E12 || (E12 = {}));
151+
// Examples of numeric enum types with constant and computed members
152+
var E20;
153+
(function (E20) {
154+
E20[E20["A"] = "foo".length] = "A";
155+
E20[E20["B"] = E20.A + 1] = "B";
156+
E20[E20["C"] = +"123"] = "C";
157+
E20[E20["D"] = Math.sin(1)] = "D";
158+
})(E20 || (E20 = {}));
159+
160+
161+
//// [enumClassification.d.ts]
162+
declare enum E01 {
163+
A = 0,
164+
}
165+
declare enum E02 {
166+
A = 123,
167+
}
168+
declare enum E03 {
169+
A = hello,
170+
}
171+
declare enum E04 {
172+
A = 0,
173+
B = 1,
174+
C = 2,
175+
}
176+
declare enum E05 {
177+
A = 0,
178+
B = 10,
179+
C = 11,
180+
}
181+
declare enum E06 {
182+
A = one,
183+
B = two,
184+
C = three,
185+
}
186+
declare enum E07 {
187+
A = 0,
188+
B = 1,
189+
C = hi,
190+
D = 10,
191+
E = 11,
192+
F = bye,
193+
}
194+
declare enum E08 {
195+
A = 10,
196+
B = hello,
197+
C = 10,
198+
D = hello,
199+
E = 10,
200+
}
201+
declare enum E10 {
202+
}
203+
declare enum E11 {
204+
A = 0,
205+
B = 1,
206+
C = 2,
207+
}
208+
declare enum E12 {
209+
A = 1,
210+
B = 2,
211+
C = 4,
212+
}
213+
declare enum E20 {
214+
A,
215+
B,
216+
C,
217+
D,
218+
}
219+
220+
221+
//// [DtsFileErrors]
222+
223+
224+
tests/cases/conformance/enums/enumClassification.d.ts(8,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
225+
tests/cases/conformance/enums/enumClassification.d.ts(21,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
226+
tests/cases/conformance/enums/enumClassification.d.ts(22,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
227+
tests/cases/conformance/enums/enumClassification.d.ts(23,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
228+
tests/cases/conformance/enums/enumClassification.d.ts(28,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
229+
tests/cases/conformance/enums/enumClassification.d.ts(31,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
230+
tests/cases/conformance/enums/enumClassification.d.ts(35,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
231+
tests/cases/conformance/enums/enumClassification.d.ts(37,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
232+
233+
234+
==== tests/cases/conformance/enums/enumClassification.d.ts (8 errors) ====
235+
declare enum E01 {
236+
A = 0,
237+
}
238+
declare enum E02 {
239+
A = 123,
240+
}
241+
declare enum E03 {
242+
A = hello,
243+
~~~~~
244+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
245+
}
246+
declare enum E04 {
247+
A = 0,
248+
B = 1,
249+
C = 2,
250+
}
251+
declare enum E05 {
252+
A = 0,
253+
B = 10,
254+
C = 11,
255+
}
256+
declare enum E06 {
257+
A = one,
258+
~~~
259+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
260+
B = two,
261+
~~~
262+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
263+
C = three,
264+
~~~~~
265+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
266+
}
267+
declare enum E07 {
268+
A = 0,
269+
B = 1,
270+
C = hi,
271+
~~
272+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
273+
D = 10,
274+
E = 11,
275+
F = bye,
276+
~~~
277+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
278+
}
279+
declare enum E08 {
280+
A = 10,
281+
B = hello,
282+
~~~~~
283+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
284+
C = 10,
285+
D = hello,
286+
~~~~~
287+
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
288+
E = 10,
289+
}
290+
declare enum E10 {
291+
}
292+
declare enum E11 {
293+
A = 0,
294+
B = 1,
295+
C = 2,
296+
}
297+
declare enum E12 {
298+
A = 1,
299+
B = 2,
300+
C = 4,
301+
}
302+
declare enum E20 {
303+
A,
304+
B,
305+
C,
306+
D,
307+
}
308+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.