File: controlFlowInstanceofExtendsFunction.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 (88 lines) | stat: -rw-r--r-- 1,789 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
=== tests/cases/conformance/controlFlow/controlFlowInstanceofExtendsFunction.ts ===
declare global {
>global : any

    interface Function {
        now(): string;
>now : () => string
    }
}

Function.prototype.now = function () {
>Function.prototype.now = function () {    return "now"} : () => string
>Function.prototype.now : () => string
>Function.prototype : Function
>Function : FunctionConstructor
>prototype : Function
>now : () => string
>function () {    return "now"} : () => string

    return "now"
>"now" : "now"
}

class X {
>X : X

    static now() {
>now : () => {}

        return {}
>{} : {}
    }

    why() {
>why : () => void

    }
}

class Y {
>Y : Y

}

console.log(X.now()) // works as expected
>console.log(X.now()) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>X.now() : {}
>X.now : () => {}
>X : typeof X
>now : () => {}

console.log(Y.now()) // works as expected
>console.log(Y.now()) : void
>console.log : (message?: any, ...optionalParams: any[]) => void
>console : Console
>log : (message?: any, ...optionalParams: any[]) => void
>Y.now() : string
>Y.now : () => string
>Y : typeof Y
>now : () => string

export const x: X | number = Math.random() > 0.5 ? new X() : 1
>x : number | X
>Math.random() > 0.5 ? new X() : 1 : X | 1
>Math.random() > 0.5 : boolean
>Math.random() : number
>Math.random : () => number
>Math : Math
>random : () => number
>0.5 : 0.5
>new X() : X
>X : typeof X
>1 : 1

if (x instanceof X) {
>x instanceof X : boolean
>x : number | X
>X : typeof X

    x.why() // should compile
>x.why() : void
>x.why : () => void
>x : X
>why : () => void
}