File: constEnumPropertyAccess2.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (34 lines) | stat: -rw-r--r-- 1,759 bytes parent folder | download | duplicates (2)
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
tests/cases/conformance/constEnums/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.
tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(14,12): error TS2476: A const enum member can only be accessed using a string literal.
tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(16,1): error TS2322: Type '"string"' is not assignable to type 'G'.
tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(18,3): error TS2540: Cannot assign to 'B' because it is a read-only property.


==== 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 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.