File: es6ClassTest2.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 (424 lines) | stat: -rw-r--r-- 8,114 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
=== tests/cases/compiler/es6ClassTest2.ts ===
class BasicMonster {
>BasicMonster : BasicMonster

    constructor(public name: string, public health: number) {
>name : string
>health : number

    }

    attack(target) {
>attack : (target: any) => void
>target : any

      // WScript.Echo("Attacks " + target);
    }

    isAlive = true;
>isAlive : boolean
>true : true
}

var m1 = new BasicMonster("1", 100);
>m1 : BasicMonster
>new BasicMonster("1", 100) : BasicMonster
>BasicMonster : typeof BasicMonster
>"1" : "1"
>100 : 100

var m2 = new BasicMonster("2", 100);
>m2 : BasicMonster
>new BasicMonster("2", 100) : BasicMonster
>BasicMonster : typeof BasicMonster
>"2" : "2"
>100 : 100

m1.attack(m2);
>m1.attack(m2) : void
>m1.attack : (target: any) => void
>m1 : BasicMonster
>attack : (target: any) => void
>m2 : BasicMonster

m1.health = 0;
>m1.health = 0 : 0
>m1.health : number
>m1 : BasicMonster
>health : number
>0 : 0

console.log((<any>m5.isAlive).toString());
>console.log((<any>m5.isAlive).toString()) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>(<any>m5.isAlive).toString() : any
>(<any>m5.isAlive).toString : any
>(<any>m5.isAlive) : any
><any>m5.isAlive : any
>m5.isAlive : boolean
>m5 : OverloadedMonster
>isAlive : boolean
>toString : any

class GetSetMonster {
>GetSetMonster : GetSetMonster

    constructor(public name: string, private _health: number) {
>name : string
>_health : number

    }

    attack(target) {
>attack : (target: any) => void
>target : any

      // WScript.Echo("Attacks " + target);
    }
  // The contextual keyword "get" followed by an identifier and
  // a curly body defines a getter in the same way that "get"
  // defines one in an object literal.
    get isAlive() {
>isAlive : boolean

        return this._health > 0;
>this._health > 0 : boolean
>this._health : number
>this : this
>_health : number
>0 : 0
    }

  // Likewise, "set" can be used to define setters.
    set health(value: number) {
>health : number
>value : number

        if (value < 0) {
>value < 0 : boolean
>value : number
>0 : 0

            throw new Error('Health must be non-negative.')
>new Error('Health must be non-negative.') : Error
>Error : ErrorConstructor
>'Health must be non-negative.' : "Health must be non-negative."
    }
        this._health = value
>this._health = value : number
>this._health : number
>this : this
>_health : number
>value : number
  }
}

var m3 = new BasicMonster("1", 100);
>m3 : BasicMonster
>new BasicMonster("1", 100) : BasicMonster
>BasicMonster : typeof BasicMonster
>"1" : "1"
>100 : 100

var m4 = new BasicMonster("2", 100);
>m4 : BasicMonster
>new BasicMonster("2", 100) : BasicMonster
>BasicMonster : typeof BasicMonster
>"2" : "2"
>100 : 100

m3.attack(m4);
>m3.attack(m4) : void
>m3.attack : (target: any) => void
>m3 : BasicMonster
>attack : (target: any) => void
>m4 : BasicMonster

m3.health = 0;
>m3.health = 0 : 0
>m3.health : number
>m3 : BasicMonster
>health : number
>0 : 0

var x = (<any>m5.isAlive).toString()
>x : any
>(<any>m5.isAlive).toString() : any
>(<any>m5.isAlive).toString : any
>(<any>m5.isAlive) : any
><any>m5.isAlive : any
>m5.isAlive : boolean
>m5 : OverloadedMonster
>isAlive : boolean
>toString : any

class OverloadedMonster {
>OverloadedMonster : OverloadedMonster

    constructor(name: string);
>name : string

    constructor(public name: string, public health?: number) {
>name : string
>health : number

    }

    attack();
>attack : { (): any; (a: any): any; }

    attack(a: any);
>attack : { (): any; (a: any): any; }
>a : any

    attack(target?) {
>attack : { (): any; (a: any): any; }
>target : any

        //WScript.Echo("Attacks " + target);
    }

    isAlive = true;
>isAlive : boolean
>true : true
}

var m5 = new OverloadedMonster("1");
>m5 : OverloadedMonster
>new OverloadedMonster("1") : OverloadedMonster
>OverloadedMonster : typeof OverloadedMonster
>"1" : "1"

var m6 = new OverloadedMonster("2");
>m6 : OverloadedMonster
>new OverloadedMonster("2") : OverloadedMonster
>OverloadedMonster : typeof OverloadedMonster
>"2" : "2"

m5.attack(m6);
>m5.attack(m6) : any
>m5.attack : { (): any; (a: any): any; }
>m5 : OverloadedMonster
>attack : { (): any; (a: any): any; }
>m6 : OverloadedMonster

m5.health = 0;
>m5.health = 0 : 0
>m5.health : number
>m5 : OverloadedMonster
>health : number
>0 : 0

var y = (<any>m5.isAlive).toString()
>y : any
>(<any>m5.isAlive).toString() : any
>(<any>m5.isAlive).toString : any
>(<any>m5.isAlive) : any
><any>m5.isAlive : any
>m5.isAlive : boolean
>m5 : OverloadedMonster
>isAlive : boolean
>toString : any

class SplatMonster {
>SplatMonster : SplatMonster

    constructor(...args: string[]) { }
>args : string[]

    roar(name: string, ...args: number[]) { }
>roar : (name: string, ...args: number[]) => void
>name : string
>args : number[]
}


function foo() { return true; }
>foo : () => boolean
>true : true

class PrototypeMonster {
>PrototypeMonster : PrototypeMonster

    age: number = 1;
>age : number
>1 : 1

    name: string;
>name : string

    b = foo();
>b : boolean
>foo() : boolean
>foo : () => boolean
}

class SuperParent {
>SuperParent : SuperParent

    constructor(a: number) {
>a : number

    }

    b(b: string) {
>b : (b: string) => void
>b : string

    }

    c() {
>c : () => void

    }
}

class SuperChild extends SuperParent {
>SuperChild : SuperChild
>SuperParent : SuperParent

    constructor() {
        super(1);
>super(1) : void
>super : typeof SuperParent
>1 : 1
    }

    b() {
>b : () => void

        super.b('str');
>super.b('str') : void
>super.b : (b: string) => void
>super : SuperParent
>b : (b: string) => void
>'str' : "str"
    }

    c() {
>c : () => void

        super.c();
>super.c() : void
>super.c : () => void
>super : SuperParent
>c : () => void
    }
}

class Statics {
>Statics : Statics

    static foo = 1;
>foo : number
>1 : 1

    static bar: string;
>bar : string

    static baz() {
>baz : () => string

        return "";
>"" : ""
    }
}

var stat = new Statics();
>stat : Statics
>new Statics() : Statics
>Statics : typeof Statics

interface IFoo {
    x: number;
>x : number

    z: string;
>z : string
}

class ImplementsInterface implements IFoo {
>ImplementsInterface : ImplementsInterface

    public x: number;
>x : number

    public z: string;
>z : string

    constructor() {
        this.x = 1;
>this.x = 1 : 1
>this.x : number
>this : this
>x : number
>1 : 1

        this.z = "foo";
>this.z = "foo" : "foo"
>this.z : string
>this : this
>z : string
>"foo" : "foo"
    }
}

class Visibility {
>Visibility : Visibility

    public foo() { }
>foo : () => void

    private bar() { }
>bar : () => void

    private x: number;
>x : number

    public y: number;
>y : number

    public z: number;
>z : number

    constructor() {
        this.x = 1;
>this.x = 1 : 1
>this.x : number
>this : this
>x : number
>1 : 1

        this.y = 2;
>this.y = 2 : 2
>this.y : number
>this : this
>y : number
>2 : 2
    }
}

class BaseClassWithConstructor {
>BaseClassWithConstructor : BaseClassWithConstructor

    constructor(public x: number, public s: string) { }
>x : number
>s : string
}

// used to test codegen
class ChildClassWithoutConstructor extends BaseClassWithConstructor { }
>ChildClassWithoutConstructor : ChildClassWithoutConstructor
>BaseClassWithConstructor : BaseClassWithConstructor


var ccwc = new ChildClassWithoutConstructor(1, "s");
>ccwc : ChildClassWithoutConstructor
>new ChildClassWithoutConstructor(1, "s") : ChildClassWithoutConstructor
>ChildClassWithoutConstructor : typeof ChildClassWithoutConstructor
>1 : 1
>"s" : "s"