File: looseThisTypeInFunctions.types

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (206 lines) | stat: -rw-r--r-- 6,033 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
=== tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts ===
interface I {
    n: number;
>n : number

    explicitThis(this: this, m: number): number;
>explicitThis : (this: this, m: number) => number
>this : this
>m : number
}
interface Unused {
    implicitNoThis(m: number): number;
>implicitNoThis : (m: number) => number
>m : number
}
class C implements I {
>C : C

    n: number;
>n : number

    explicitThis(this: this, m: number): number {
>explicitThis : (this: this, m: number) => number
>this : this
>m : number

        return this.n + m;
>this.n + m : number
>this.n : number
>this : this
>n : number
>m : number
    }
    implicitThis(m: number): number {
>implicitThis : (m: number) => number
>m : number

        return this.n + m;
>this.n + m : number
>this.n : number
>this : this
>n : number
>m : number
    }
    explicitVoid(this: void, m: number): number {
>explicitVoid : (this: void, m: number) => number
>this : void
>m : number

        return m + 1;
>m + 1 : number
>m : number
>1 : 1
    }
}
let c = new C();
>c : C
>new C() : C
>C : typeof C

c.explicitVoid = c.explicitThis; // error, 'void' is missing everything
>c.explicitVoid = c.explicitThis : (this: C, m: number) => number
>c.explicitVoid : (this: void, m: number) => number
>c : C
>explicitVoid : (this: void, m: number) => number
>c.explicitThis : (this: C, m: number) => number
>c : C
>explicitThis : (this: C, m: number) => number

let o = {
>o : { n: number; explicitThis: (m: number) => any; implicitThis(m: number): number; }
>{    n: 101,    explicitThis: function (m: number) {        return m + this.n.length; // error, 'length' does not exist on 'number'    },    implicitThis(m: number): number { return m; }} : { n: number; explicitThis: (m: number) => any; implicitThis(m: number): number; }

    n: 101,
>n : number
>101 : 101

    explicitThis: function (m: number) {
>explicitThis : (m: number) => any
>function (m: number) {        return m + this.n.length; // error, 'length' does not exist on 'number'    } : (m: number) => any
>m : number

        return m + this.n.length; // error, 'length' does not exist on 'number'
>m + this.n.length : any
>m : number
>this.n.length : any
>this.n : number
>this : { n: number; explicitThis: (m: number) => any; implicitThis(m: number): number; }
>n : number
>length : any

    },
    implicitThis(m: number): number { return m; }
>implicitThis : (m: number) => number
>m : number
>m : number

};
let i: I = o;
>i : I
>o : { n: number; explicitThis: (m: number) => any; implicitThis(m: number): number; }

let o2: I = {
>o2 : I
>{    n: 1001,    explicitThis: function (m) {         return m + this.n.length;  // error, this.n: number, no member 'length'    },} : { n: number; explicitThis: (this: I, m: number) => any; }

    n: 1001,
>n : number
>1001 : 1001

    explicitThis: function (m) {
>explicitThis : (this: I, m: number) => any
>function (m) {         return m + this.n.length;  // error, this.n: number, no member 'length'    } : (this: I, m: number) => any
>m : number

         return m + this.n.length;  // error, this.n: number, no member 'length'
>m + this.n.length : any
>m : number
>this.n.length : any
>this.n : number
>this : I
>n : number
>length : any

    },
}
let x = i.explicitThis;
>x : (this: I, m: number) => number
>i.explicitThis : (this: I, m: number) => number
>i : I
>explicitThis : (this: I, m: number) => number

let n = x(12); // callee:void doesn't match this:I
>n : number
>x(12) : number
>x : (this: I, m: number) => number
>12 : 12

let u: Unused;
>u : Unused

let y = u.implicitNoThis;
>y : (m: number) => number
>u.implicitNoThis : (m: number) => number
>u : Unused
>implicitNoThis : (m: number) => number

n = y(12); // ok, callee:void matches this:any
>n = y(12) : number
>n : number
>y(12) : number
>y : (m: number) => number
>12 : 12

c.explicitVoid = c.implicitThis // ok, implicitThis(this:any)
>c.explicitVoid = c.implicitThis : (m: number) => number
>c.explicitVoid : (this: void, m: number) => number
>c : C
>explicitVoid : (this: void, m: number) => number
>c.implicitThis : (m: number) => number
>c : C
>implicitThis : (m: number) => number

o.implicitThis = c.implicitThis; // ok, implicitThis(this:any)
>o.implicitThis = c.implicitThis : (m: number) => number
>o.implicitThis : (m: number) => number
>o : { n: number; explicitThis: (m: number) => any; implicitThis(m: number): number; }
>implicitThis : (m: number) => number
>c.implicitThis : (m: number) => number
>c : C
>implicitThis : (m: number) => number

o.implicitThis = c.explicitThis; // ok, implicitThis(this:any) is assignable to explicitThis(this: this)
>o.implicitThis = c.explicitThis : (this: C, m: number) => number
>o.implicitThis : (m: number) => number
>o : { n: number; explicitThis: (m: number) => any; implicitThis(m: number): number; }
>implicitThis : (m: number) => number
>c.explicitThis : (this: C, m: number) => number
>c : C
>explicitThis : (this: C, m: number) => number

o.implicitThis = i.explicitThis;
>o.implicitThis = i.explicitThis : (this: I, m: number) => number
>o.implicitThis : (m: number) => number
>o : { n: number; explicitThis: (m: number) => any; implicitThis(m: number): number; }
>implicitThis : (m: number) => number
>i.explicitThis : (this: I, m: number) => number
>i : I
>explicitThis : (this: I, m: number) => number

i.explicitThis = function(m) {
>i.explicitThis = function(m) {     return this.n.length;  // error, this.n: number} : (this: I, m: number) => any
>i.explicitThis : (this: I, m: number) => number
>i : I
>explicitThis : (this: I, m: number) => number
>function(m) {     return this.n.length;  // error, this.n: number} : (this: I, m: number) => any
>m : number

     return this.n.length;  // error, this.n: number
>this.n.length : any
>this.n : number
>this : I
>n : number
>length : any
}