File: enumAssignmentCompat5.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 (36 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download
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
tests/cases/compiler/enumAssignmentCompat5.ts(12,1): error TS2322: Type '4' is not assignable to type 'E'.
tests/cases/compiler/enumAssignmentCompat5.ts(14,1): error TS2322: Type '2' is not assignable to type 'E.A'.
tests/cases/compiler/enumAssignmentCompat5.ts(20,5): error TS2322: Type '1' is not assignable to type 'Computed.A'.


==== tests/cases/compiler/enumAssignmentCompat5.ts (3 errors) ====
    enum E {
        A, B, C
    }
    enum Computed {
        A = 1 << 1,
        B = 1 << 2,
        C = 1 << 3,
    }
    let n: number;
    let e: E = n; // ok because it's too inconvenient otherwise
    e = 0; // ok, in range
    e = 4; // ok, out of range, but allowed computed enums don't have all members
    ~
!!! error TS2322: Type '4' is not assignable to type 'E'.
    let a: E.A = 0; // ok, A === 0
    a = 2; // error, 2 !== 0
    ~
!!! error TS2322: Type '2' is not assignable to type 'E.A'.
    a = n; // ok
    
    let c: Computed = n; // ok
    c = n; // ok
    c = 4; // ok
    let ca: Computed.A = 1; // error, Computed.A isn't a literal type because Computed has no enum literals
        ~~
!!! error TS2322: Type '1' is not assignable to type 'Computed.A'.