• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Enumeration members can be initialized only with compile time expressions of the same type
2
3Rule ``arkts-no-enum-mixed-types``
4
5**Severity: error**
6
7ArkTS does not support initializing members of enumerations with expressions
8that are evaluated during program runtime. Besides, all explicitly set
9initializers must be of the same type.
10
11
12## TypeScript
13
14
15```
16
17    enum E1 {
18        A = 0xa,
19        B = 0xb,
20        C = Math.random(),
21        D = 0xd,
22        E // 0xe inferred
23    }
24
25    enum E2 {
26        A = 0xa,
27        B = "0xb",
28        C = 0xc,
29        D = "0xd"
30    }
31
32```
33
34## ArkTS
35
36
37```
38
39    enum E1 {
40        A = 0xa,
41        B = 0xb,
42        C = 0xc,
43        D = 0xd,
44        E // 0xe inferred
45    }
46
47    enum E2 {
48        A = "0xa",
49        B = "0xb",
50        C = "0xc",
51        D = "0xd"
52    }
53
54```
55
56
57