File: thisTypeInFunctions2.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 (146 lines) | stat: -rw-r--r-- 4,300 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
=== tests/cases/conformance/types/thisType/thisTypeInFunctions2.ts ===
interface IndexedWithThis {
    // this is a workaround for React
    init?: (this: this) => void;
>init : (this: this) => void
>this : this

    willDestroy?: (this: any) => void;
>willDestroy : (this: any) => void
>this : any

    [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any);
>propName : string
>null : null
>this : any
>args : any[]
}
interface IndexedWithoutThis {
    // this is what React would like to write (and what they write today)
    init?: () => void;
>init : () => void

    willDestroy?: () => void;
>willDestroy : () => void

    [propName: string]: any;
>propName : string
}
interface SimpleInterface {
    foo(n: string);
>foo : (n: string) => any
>n : string

    bar(): number;
>bar : () => number
}
declare function extend1(args: IndexedWithThis): void;
>extend1 : (args: IndexedWithThis) => void
>args : IndexedWithThis

declare function extend2(args: IndexedWithoutThis): void;
>extend2 : (args: IndexedWithoutThis) => void
>args : IndexedWithoutThis

declare function simple(arg: SimpleInterface): void;
>simple : (arg: SimpleInterface) => void
>arg : SimpleInterface

extend1({
>extend1({    init() {        this // this: IndexedWithThis because of contextual typing.        // this.mine        this.willDestroy    },    mine: 12,    foo() {        this.url; // this: any because 'foo' matches the string indexer        this.willDestroy;    }}) : void
>extend1 : (args: IndexedWithThis) => void
>{    init() {        this // this: IndexedWithThis because of contextual typing.        // this.mine        this.willDestroy    },    mine: 12,    foo() {        this.url; // this: any because 'foo' matches the string indexer        this.willDestroy;    }} : { init(this: IndexedWithThis): void; mine: number; foo(this: any): void; }

    init() {
>init : (this: IndexedWithThis) => void

        this // this: IndexedWithThis because of contextual typing.
>this : IndexedWithThis

        // this.mine
        this.willDestroy
>this.willDestroy : (this: any) => void
>this : IndexedWithThis
>willDestroy : (this: any) => void

    },
    mine: 12,
>mine : number
>12 : 12

    foo() {
>foo : (this: any) => void

        this.url; // this: any because 'foo' matches the string indexer
>this.url : any
>this : any
>url : any

        this.willDestroy;
>this.willDestroy : any
>this : any
>willDestroy : any
    }
});
extend2({
>extend2({    init() {        this // this: IndexedWithoutThis because of contextual typing        this.mine    },    mine: 13,    foo() {        this // this: IndexedWithoutThis because of contextual typing        this.mine    }}) : void
>extend2 : (args: IndexedWithoutThis) => void
>{    init() {        this // this: IndexedWithoutThis because of contextual typing        this.mine    },    mine: 13,    foo() {        this // this: IndexedWithoutThis because of contextual typing        this.mine    }} : { init(): void; mine: number; foo(): void; }

    init() {
>init : () => void

        this // this: IndexedWithoutThis because of contextual typing
>this : IndexedWithoutThis

        this.mine
>this.mine : any
>this : IndexedWithoutThis
>mine : any

    },
    mine: 13,
>mine : number
>13 : 13

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

        this // this: IndexedWithoutThis because of contextual typing
>this : IndexedWithoutThis

        this.mine
>this.mine : any
>this : IndexedWithoutThis
>mine : any
    }
});

simple({
>simple({    foo(n) {        return n.length + this.bar();    },    bar() {        return 14;    }}) : void
>simple : (arg: SimpleInterface) => void
>{    foo(n) {        return n.length + this.bar();    },    bar() {        return 14;    }} : { foo(n: string): number; bar(): number; }

    foo(n) {
>foo : (n: string) => number
>n : string

        return n.length + this.bar();
>n.length + this.bar() : number
>n.length : number
>n : string
>length : number
>this.bar() : number
>this.bar : () => number
>this : SimpleInterface
>bar : () => number

    },
    bar() {
>bar : () => number

        return 14;
>14 : 14
    }
})