File: functionImplementationErrors.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (192 lines) | stat: -rw-r--r-- 4,189 bytes parent folder | download | duplicates (5)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
=== tests/cases/conformance/functions/functionImplementationErrors.ts ===
// FunctionExpression with no return type annotation with multiple return statements with unrelated types
var f1 = function () {
>f1 : () => "" | 3
>function () {    return '';    return 3;} : () => "" | 3

    return '';
>'' : ""

    return 3;
>3 : 3

};
var f2 = function x() {
>f2 : () => "" | 3
>function x() {    return '';    return 3;} : () => "" | 3
>x : () => "" | 3

    return '';
>'' : ""

    return 3;
>3 : 3

};
var f3 = () => {
>f3 : () => "" | 3
>() => {    return '';    return 3;} : () => "" | 3

    return '';
>'' : ""

    return 3;
>3 : 3

};

// FunctionExpression with no return type annotation with return branch of number[] and other of string[]
var f4 = function () {
>f4 : () => string[] | number[]
>function () {    if (true) {        return [''];    } else {        return [1];    }} : () => string[] | number[]

    if (true) {
>true : true

        return [''];
>[''] : string[]
>'' : ""

    } else {
        return [1];
>[1] : number[]
>1 : 1
    }
}

// Function implemetnation with non -void return type annotation with no return
function f5(): number {
>f5 : () => number
}

var m;
>m : any

// Function signature with parameter initializer referencing in scope local variable
function f6(n = m) {
>f6 : (n?: number) => void
>n : number
>m : number

    var m = 4;
>m : number
>4 : 4
}

// Function signature with initializer referencing other parameter to the right
function f7(n = m, m?) {
>f7 : (n?: any, m?: any) => void
>n : any
>m : any
>m : any
}

// FunctionExpression with non -void return type annotation with a throw, no return, and other code
// Should be error but isn't
undefined === function (): number {
>undefined === function (): number {    throw undefined;    var x = 4;} : boolean
>undefined : undefined
>function (): number {    throw undefined;    var x = 4;} : () => number

    throw undefined;
>undefined : undefined

    var x = 4;
>x : number
>4 : 4

};

class Base { private x; }
>Base : Base
>x : any

class AnotherClass { private y; }
>AnotherClass : AnotherClass
>y : any

class Derived1 extends Base { private m; }
>Derived1 : Derived1
>Base : Base
>m : any

class Derived2 extends Base { private n; }
>Derived2 : Derived2
>Base : Base
>n : any

function f8() {
>f8 : () => Derived1 | Derived2

    return new Derived1();
>new Derived1() : Derived1
>Derived1 : typeof Derived1

    return new Derived2();    
>new Derived2() : Derived2
>Derived2 : typeof Derived2
}
var f9 = function () {
>f9 : () => Derived1 | Derived2
>function () {    return new Derived1();    return new Derived2();} : () => Derived1 | Derived2

    return new Derived1();
>new Derived1() : Derived1
>Derived1 : typeof Derived1

    return new Derived2();
>new Derived2() : Derived2
>Derived2 : typeof Derived2

};
var f10 = () => {
>f10 : () => Derived1 | Derived2
>() => {    return new Derived1();    return new Derived2();} : () => Derived1 | Derived2

    return new Derived1();
>new Derived1() : Derived1
>Derived1 : typeof Derived1

    return new Derived2();
>new Derived2() : Derived2
>Derived2 : typeof Derived2

};
function f11() {
>f11 : () => Base | AnotherClass

    return new Base();
>new Base() : Base
>Base : typeof Base

    return new AnotherClass();
>new AnotherClass() : AnotherClass
>AnotherClass : typeof AnotherClass
}
var f12 = function () {
>f12 : () => Base | AnotherClass
>function () {    return new Base();    return new AnotherClass();} : () => Base | AnotherClass

    return new Base();
>new Base() : Base
>Base : typeof Base

    return new AnotherClass();
>new AnotherClass() : AnotherClass
>AnotherClass : typeof AnotherClass

};
var f13 = () => {
>f13 : () => Base | AnotherClass
>() => {    return new Base();    return new AnotherClass();} : () => Base | AnotherClass

    return new Base();
>new Base() : Base
>Base : typeof Base

    return new AnotherClass();
>new AnotherClass() : AnotherClass
>AnotherClass : typeof AnotherClass

};