mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
34 lines
1.5 KiB
Plaintext
34 lines
1.5 KiB
Plaintext
constEnumPropertyAccess2.ts(13,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 or type query.
|
|
constEnumPropertyAccess2.ts(14,12): error TS2476: A const enum member can only be accessed using a string literal.
|
|
constEnumPropertyAccess2.ts(16,1): error TS2322: Type '"string"' is not assignable to type 'G'.
|
|
constEnumPropertyAccess2.ts(18,3): error TS2540: Cannot assign to 'B' because it is a read-only property.
|
|
|
|
|
|
==== 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 or type query.
|
|
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 TS2540: Cannot assign to 'B' because it is a read-only property.
|
|
|