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
|
=== tests/cases/conformance/enums/enumErrors.ts ===
// Enum named with PredefinedTypes
enum any { }
>any : any
enum number { }
>number : number
enum string { }
>string : string
enum boolean { }
>boolean : boolean
// Enum with computed member initializer of type Number
enum E5 {
>E5 : E5
C = new Number(30)
>C : E5
>new Number(30) : Number
>Number : NumberConstructor
>30 : 30
}
enum E9 {
>E9 : E9
A,
>A : E9.A
B = A
>B : E9.A
>A : E9
}
//Enum with computed member intializer of different enum type
// Bug 707850: This should be allowed
enum E10 {
>E10 : E10
A = E9.A,
>A : E10
>E9.A : E9
>E9 : typeof E9
>A : E9
B = E9.B
>B : E10
>E9.B : E9
>E9 : typeof E9
>B : E9
}
// Enum with computed member intializer of other types
enum E11 {
>E11 : E11
A = true,
>A : E11
>true : true
B = new Date(),
>B : E11
>new Date() : Date
>Date : DateConstructor
C = window,
>C : E11
>window : Window & typeof globalThis
D = {},
>D : E11
>{} : {}
E = (() => 'foo')(),
>E : E11
>(() => 'foo')() : string
>(() => 'foo') : () => string
>() => 'foo' : () => string
>'foo' : "foo"
}
// Enum with string valued member and computed member initializers
enum E12 {
>E12 : E12
A = '',
>A : E12.A
>'' : ""
B = new Date(),
>B : E12.B
>new Date() : Date
>Date : DateConstructor
C = window,
>C : E12.B
>window : Window & typeof globalThis
D = {},
>D : E12.B
>{} : {}
E = 1 + 1,
>E : E12.B
>1 + 1 : number
>1 : 1
>1 : 1
F = (() => 'foo')(),
>F : E12.B
>(() => 'foo')() : string
>(() => 'foo') : () => string
>() => 'foo' : () => string
>'foo' : "foo"
}
// Enum with incorrect syntax
enum E13 {
>E13 : E13
postComma,
>postComma : E13.postComma
postValueComma = 1,
>postValueComma : E13.postValueComma
>1 : 1
postSemicolon;
>postSemicolon : E13.postSemicolon
postColonValueComma: 2,
>postColonValueComma : E13.postColonValueComma
>2 : (typeof E13)["2"]
postColonValueSemicolon: 3;
>postColonValueSemicolon : E13.postColonValueSemicolon
>3 : (typeof E13)["3"]
};
enum E14 { a, b: any "hello" += 1, c, d}
>E14 : E14
>a : E14.a
>b : E14.b
>any : E14.any
>"hello" : E14.hello
>1 : (typeof E14)["1"]
>c : E14.c
>d : E14.d
|