1
1
enumLiteralBasics.ts(6,5): error TS1061: Enum member must have initializer.
2
2
enumLiteralBasics.ts(7,5): error TS1061: Enum member must have initializer.
3
- enumLiteralBasics.ts(21,7): error TS2322: Type '"exists"' is not assignable to type 'E1'.
4
- enumLiteralBasics.ts(23,7): error TS2322: Type '"string"' is not assignable to type 'E1'.
5
- enumLiteralBasics.ts(33,33): error TS2345: Argument of type '"exists"' is not assignable to parameter of type 'E1'.
6
- enumLiteralBasics.ts(38,32): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'E1'.
3
+ enumLiteralBasics.ts(22,1): error TS2322: Type 'E1.Flag' is not assignable to type 'E1.Int'.
4
+ enumLiteralBasics.ts(27,7): error TS2322: Type '"exists"' is not assignable to type 'E1'.
5
+ enumLiteralBasics.ts(29,7): error TS2322: Type '"string"' is not assignable to type 'E1'.
6
+ enumLiteralBasics.ts(39,33): error TS2345: Argument of type '"exists"' is not assignable to parameter of type 'E1'.
7
+ enumLiteralBasics.ts(44,32): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'E1'.
8
+ enumLiteralBasics.ts(52,38): error TS2345: Argument of type '"exists"' is not assignable to parameter of type 'E1.Int'.
9
+ enumLiteralBasics.ts(54,38): error TS2345: Argument of type '4' is not assignable to parameter of type 'E1.Int'.
10
+ enumLiteralBasics.ts(56,38): error TS2345: Argument of type 'E1.String' is not assignable to parameter of type 'E1.Int'.
11
+ enumLiteralBasics.ts(57,7): error TS2322: Type 'E1.Int' is not assignable to type 'E1.Flag'.
12
+ enumLiteralBasics.ts(57,38): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'E1.Int'.
7
13
8
14
9
- ==== enumLiteralBasics.ts (6 errors) ====
15
+ ==== enumLiteralBasics.ts (12 errors) ====
10
16
// Enum without initializers have first member = 0 and successive members = N + 1
11
17
12
18
// Enum literal syntax does not implement auto-incrementing behaviour.
@@ -28,6 +34,14 @@ enumLiteralBasics.ts(38,32): error TS2345: Argument of type '"string"' is not as
28
34
const exist: E1 = E1.ExistingShorthand; // ok
29
35
const ival: E1 = E1.Int; // ok
30
36
const sval: E1 = E1.String; // ok
37
+ let p_int: E1.Int = E1.Int; // ok
38
+ const p_nonexist: E1.NonexistingShorthand = E1.NonexistingShorthand; // ok
39
+ const p_exist: E1.ExistingShorthand = E1.ExistingShorthand; // ok
40
+ const p_string: E1.String = E1.String; // ok
41
+ p_int = E1.Flag; // Type 'E1.Flag' is not assignable to type 'E1.Int'.
42
+ ~~~~~
43
+ !!! error TS2322: Type 'E1.Flag' is not assignable to type 'E1.Int'.
44
+ p_int = E1.Int | E1.Flag;
31
45
32
46
// Assigning values which are not part of the enum despite being present in the enum
33
47
const nonexist_bad: E1 = undefined; // error
@@ -57,4 +71,26 @@ enumLiteralBasics.ts(38,32): error TS2345: Argument of type '"string"' is not as
57
71
const sval_bad2: E1 = functest("string"); // error
58
72
~~~~~~~~
59
73
!!! error TS2345: Argument of type '"string"' is not assignable to parameter of type 'E1'.
60
-
74
+
75
+ function functest2(value: E1.Int) {
76
+ console.log(value);
77
+ return value;
78
+ }
79
+
80
+ const nonexist_bad3: E1.Int = functest2(undefined);
81
+ const exist_bad3: E1.Int = functest2("exists"); // error
82
+ ~~~~~~~~
83
+ !!! error TS2345: Argument of type '"exists"' is not assignable to parameter of type 'E1.Int'.
84
+ const ival_good5: E1.Int = functest2(1); // ok
85
+ const ival_good6: E1.Int = functest2(4); // ok
86
+ ~
87
+ !!! error TS2345: Argument of type '4' is not assignable to parameter of type 'E1.Int'.
88
+ const ival_good7: E1.Int = functest2(E1.Int | E1.Flag); // ok
89
+ const sval_good3: E1.Int = functest2(E1.String);
90
+ ~~~~~~~~~
91
+ !!! error TS2345: Argument of type 'E1.String' is not assignable to parameter of type 'E1.Int'.
92
+ const sval_bad3: E1.Flag = functest2("string"); // error
93
+ ~~~~~~~~~
94
+ !!! error TS2322: Type 'E1.Int' is not assignable to type 'E1.Flag'.
95
+ ~~~~~~~~
96
+ !!! error TS2345: Argument of type '"string"' is not assignable to parameter of type 'E1.Int'.
0 commit comments