File: enumBasics.errors.txt

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (86 lines) | stat: -rw-r--r-- 2,447 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
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
tests/cases/conformance/enums/enumBasics.ts(13,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'e' must be of type 'typeof E1', but here has type '{ readonly [n: number]: string; readonly A: E1; readonly B: E1; readonly C: E1; }'.


==== tests/cases/conformance/enums/enumBasics.ts (1 errors) ====
    // Enum without initializers have first member = 0 and successive members = N + 1
    enum E1 {
        A,
        B,
        C
    }
    
    // Enum type is a subtype of Number
    var x: number = E1.A;
    
    // Enum object type is anonymous with properties of the enum type and numeric indexer
    var e = E1;
    var e: {
        ~
!!! error TS2403: Subsequent variable declarations must have the same type.  Variable 'e' must be of type 'typeof E1', but here has type '{ readonly [n: number]: string; readonly A: E1; readonly B: E1; readonly C: E1; }'.
        readonly A: E1;
        readonly B: E1;
        readonly C: E1;
        readonly [n: number]: string;
    };
    var e: typeof E1;
    
    // Reverse mapping of enum returns string name of property 
    var s = E1[e.A];
    var s: string;
    
    
    // Enum with only constant members
    enum E2 {
        A = 1, B = 2, C = 3
    }
    
    // Enum with only computed members
    enum E3 {
        X = 'foo'.length, Y = 4 + 3, Z = +'foo'
    }
    
    // Enum with constant members followed by computed members
    enum E4 {
        X = 0, Y, Z = 'foo'.length
    }
    
    // Enum with > 2 constant members with no initializer for first member, non zero initializer for second element
    enum E5 {
        A,
        B = 3,
        C // 4
    }
    
    enum E6 {
        A,
        B = 0,
        C // 1
    }
    
    // Enum with computed member initializer of type 'any'
    enum E7 {
        A = 'foo'['foo']
    }
    
    // Enum with computed member initializer of type number
    enum E8 {
        B = 'foo'['foo']
    }
    
    //Enum with computed member intializer of same enum type
    enum E9 {
        A,
        B = A
    }
    
    // (refer to .js to validate)
    // Enum constant members are propagated
    var doNotPropagate = [
        E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z
    ];
    // Enum computed members are not propagated
    var doPropagate = [
        E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C
    ];