File: arrowFunctionContexts.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 (116 lines) | stat: -rw-r--r-- 4,609 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(2,1): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(30,9): error TS18033: Type '() => number' is not assignable to type 'number' as required for computed enum member values.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(31,16): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(43,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(71,13): error TS18033: Type '() => number' is not assignable to type 'number' as required for computed enum member values.
tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts(72,20): error TS2332: 'this' cannot be referenced in current location.


==== tests/cases/conformance/expressions/functions/arrowFunctionContexts.ts (6 errors) ====
    // Arrow function used in with statement
    with (window) {
    ~~~~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
        var p = () => this;
    }
    
    // Arrow function as argument to super call
    class Base {
        constructor(n: any) { }
    }
    
    class Derived extends Base {
        constructor() {
            super(() => this);
        }
    }
    
    // Arrow function as function argument
    window.setTimeout(() => null, 100);
    
    // Arrow function as value in array literal
    
    var obj = (n: number) => '';
    var obj: { (n: number): string; }; // OK
    
    var arr = [(n: number) => ''];
    var arr: { (n: number): string; }[]; // Incorrect error here (bug 829597)
    
    // Arrow function as enum value
    enum E {
        x = () => 4, // Error expected
            ~~~~~~~
!!! error TS18033: Type '() => number' is not assignable to type 'number' as required for computed enum member values.
        y = (() => this).length // error, can't use this in enum
                   ~~~~
!!! error TS2332: 'this' cannot be referenced in current location.
    }
    
    // Arrow function as module variable initializer
    module M {
        export var a = (s) => '';
        var b = (s) => s;
    }
    
    // Repeat above for module members that are functions? (necessary to redo all of them?)
    module M2 {
        // Arrow function used in with statement
        with (window) {
        ~~~~~~~~~~~~~
!!! error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
            var p = () => this;
        }
    
        // Arrow function as argument to super call
        class Base {
            constructor(n: any) { }
        }
    
        class Derived extends Base {
            constructor() {
                super(() => this);
            }
        }
    
        // Arrow function as function argument
        window.setTimeout(() => null, 100);
    
        // Arrow function as value in array literal
    
        var obj = (n: number) => '';
        var obj: { (n: number): string; }; // OK
    
        var arr = [(n: number) => ''];
        var arr: { (n: number): string; }[]; // Incorrect error here (bug 829597)
    
        // Arrow function as enum value
        enum E {
            x = () => 4, // Error expected
                ~~~~~~~
!!! error TS18033: Type '() => number' is not assignable to type 'number' as required for computed enum member values.
            y = (() => this).length
                       ~~~~
!!! error TS2332: 'this' cannot be referenced in current location.
        }
    
        // Arrow function as module variable initializer
        module M {
            export var a = (s) => '';
            var b = (s) => s;
        }
    
    }
    
    // <Identifier>(ParamList) => { ... } is a generic arrow function
    var generic1 = <T>(n: T) => [n];
    var generic1: { <T>(n: T): T[] }; // Incorrect error, Bug 829597
    var generic2 = <T>(n: T) => { return [n]; };
    var generic2: { <T>(n: T): T[] };
    
    // <Identifier> ((ParamList) => { ... } ) is a type assertion to an arrow function
    var asserted1 = <any>((n) => [n]);
    var asserted1: any;
    var asserted2 = <any>((n) => { return n; });
    var asserted2: any;