35 lines
1.7 KiB
Plaintext
35 lines
1.7 KiB
Plaintext
tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(14,9): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment.
|
|
tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(15,12): error TS2476: A const enum member can only be accessed using a string literal.
|
|
tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(17,1): error TS2322: Type 'string' is not assignable to type 'G'.
|
|
tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS2364: Invalid left-hand side of assignment expression.
|
|
|
|
|
|
==== tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts (4 errors) ====
|
|
|
|
// constant enum declarations are completely erased in the emitted JavaScript code.
|
|
// it is an error to reference a constant enum object in any other context
|
|
// than a property access that selects one of the enum's members
|
|
|
|
const enum G {
|
|
A = 1,
|
|
B = 2,
|
|
C = A + B,
|
|
D = A * 2
|
|
}
|
|
|
|
// Error from referring constant enum in any other context than a property access
|
|
var z = G;
|
|
~
|
|
!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment.
|
|
var z1 = G[G.A];
|
|
~~~
|
|
!!! error TS2476: A const enum member can only be accessed using a string literal.
|
|
var g: G;
|
|
g = "string";
|
|
~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'G'.
|
|
function foo(x: G) { }
|
|
G.B = 3;
|
|
~~~
|
|
!!! error TS2364: Invalid left-hand side of assignment expression.
|
|
|