@@ -174,69 +174,60 @@ function initializer(this: C = new C()): number { return this.n; }
174
174
175
175
// can't name parameters 'this' in a lambda.
176
176
c . explicitProperty = ( this , m ) => m + this . n ;
177
+ const f2 = < T > (this: { n : number } , m: number) => m + this . n ;
178
+ const f3 = async ( this : { n : number } , m : number ) => m + this . n ;
179
+ const f4 = async < T > ( this : { n : number } , m : number ) => m + this . n ;
177
180
178
181
179
182
//// [thisTypeInFunctionsNegative.js]
180
- var __extends = ( this && this . __extends ) || ( function ( ) {
181
- var extendStatics = function ( d , b ) {
182
- extendStatics = Object . setPrototypeOf ||
183
- ( { __proto__ : [ ] } instanceof Array && function ( d , b ) { d . __proto__ = b ; } ) ||
184
- function ( d , b ) { for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ; } ;
185
- return extendStatics ( d , b ) ;
186
- }
187
- return function ( d , b ) {
188
- extendStatics ( d , b ) ;
189
- function __ ( ) { this . constructor = d ; }
190
- d . prototype = b === null ? Object . create ( b ) : ( __ . prototype = b . prototype , new __ ( ) ) ;
191
- } ;
192
- } ) ( ) ;
193
- var _this = this ;
194
- var C = /** @class */ ( function ( ) {
195
- function C ( ) {
196
- }
197
- C . prototype . explicitThis = function ( m ) {
183
+ var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
184
+ return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
185
+ function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
186
+ function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
187
+ function step ( result ) { result . done ? resolve ( result . value ) : new P ( function ( resolve ) { resolve ( result . value ) ; } ) . then ( fulfilled , rejected ) ; }
188
+ step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
189
+ } ) ;
190
+ } ;
191
+ class C {
192
+ explicitThis ( m ) {
198
193
return this . n + m ;
199
- } ;
200
- C . prototype . implicitThis = function ( m ) {
194
+ }
195
+ implicitThis ( m ) {
201
196
return this . n + m ;
202
- } ;
203
- C . prototype . explicitC = function ( m ) {
197
+ }
198
+ explicitC ( m ) {
204
199
return this . n + m ;
205
- } ;
206
- C . prototype . explicitProperty = function ( m ) {
200
+ }
201
+ explicitProperty ( m ) {
207
202
return this . n + m ;
208
- } ;
209
- C . prototype . explicitVoid = function ( m ) {
203
+ }
204
+ explicitVoid ( m ) {
210
205
return this . n + m ; // 'n' doesn't exist on type 'void'.
211
- } ;
212
- return C ;
213
- } ( ) ) ;
214
- var D = /** @class */ ( function ( ) {
215
- function D ( ) {
216
206
}
217
- D . prototype . explicitThis = function ( m ) {
207
+ }
208
+ class D {
209
+ explicitThis ( m ) {
218
210
return this . x + m ;
219
- } ;
220
- D . prototype . explicitD = function ( m ) {
211
+ }
212
+ explicitD ( m ) {
221
213
return this . x + m ;
222
- } ;
223
- return D ;
224
- } ( ) ) ;
225
- var impl = {
214
+ }
215
+ }
216
+ let impl = {
226
217
a : 12 ,
227
- explicitVoid1 : function ( ) {
218
+ explicitVoid1 ( ) {
228
219
return this . a ; // error, no 'a' in 'void'
229
220
} ,
230
- explicitVoid2 : function ( ) { return _this . a ; } ,
231
- explicitStructural : function ( ) { return 12 ; } ,
232
- explicitInterface : function ( ) { return 12 ; } ,
233
- explicitThis : function ( ) {
221
+ explicitVoid2 : ( ) => this . a ,
222
+ explicitStructural : ( ) => 12 ,
223
+ explicitInterface : ( ) => 12 ,
224
+ explicitThis ( ) {
234
225
return this . a ;
235
- }
226
+ } ,
236
227
} ;
237
- var implExplicitStructural = impl . explicitStructural ;
228
+ let implExplicitStructural = impl . explicitStructural ;
238
229
implExplicitStructural ( ) ; // error, no 'a' in 'void'
239
- var implExplicitInterface = impl . explicitInterface ;
230
+ let implExplicitInterface = impl . explicitInterface ;
240
231
implExplicitInterface ( ) ; // error, no 'a' in 'void'
241
232
function explicitStructural ( x ) {
242
233
return x + this . y ;
@@ -247,15 +238,15 @@ function propertyName(x) {
247
238
function voidThisSpecified ( x ) {
248
239
return x + this . notSpecified ;
249
240
}
250
- var ok = { y : 12 , explicitStructural : explicitStructural } ;
251
- var wrongPropertyType = { y : 'foo' , explicitStructural : explicitStructural } ;
252
- var wrongPropertyName = { wrongName : 12 , explicitStructural : explicitStructural } ;
241
+ let ok = { y : 12 , explicitStructural } ;
242
+ let wrongPropertyType = { y : 'foo' , explicitStructural } ;
243
+ let wrongPropertyName = { wrongName : 12 , explicitStructural } ;
253
244
ok . f ( ) ; // not enough arguments
254
245
ok . f ( 'wrong type' ) ;
255
246
ok . f ( 13 , 'too many arguments' ) ;
256
247
wrongPropertyType . f ( 13 ) ;
257
248
wrongPropertyName . f ( 13 ) ;
258
- var c = new C ( ) ;
249
+ let c = new C ( ) ;
259
250
c . explicitC ( ) ; // not enough arguments
260
251
c . explicitC ( 'wrong type' ) ;
261
252
c . explicitC ( 13 , 'too many arguments' ) ;
@@ -269,8 +260,8 @@ c.explicitProperty(); // not enough arguments
269
260
c . explicitProperty ( 'wrong type 3' ) ;
270
261
c . explicitProperty ( 15 , 'too many arguments 3' ) ;
271
262
// oops, this triggers contextual typing, which needs to be updated to understand that =>'s `this` is void.
272
- var specifiedToVoid = explicitStructural ;
273
- var reconstructed = {
263
+ let specifiedToVoid = explicitStructural ;
264
+ let reconstructed = {
274
265
n : 12 ,
275
266
explicitThis : c . explicitThis ,
276
267
explicitC : c . explicitC ,
@@ -279,8 +270,8 @@ var reconstructed = {
279
270
} ;
280
271
;
281
272
// lambdas have this: void for assignability purposes (and this unbound (free) for body checking)
282
- var d = new D ( ) ;
283
- var explicitXProperty ;
273
+ let d = new D ( ) ;
274
+ let explicitXProperty ;
284
275
// from differing object types
285
276
c . explicitC = function ( m ) { return this . x + m ; } ;
286
277
c . explicitProperty = explicitXProperty ;
@@ -293,64 +284,41 @@ c.explicitThis = d.explicitThis;
293
284
c . explicitVoid = d . explicitD ;
294
285
c . explicitVoid = d . explicitThis ;
295
286
/// class-based polymorphic assignability (with inheritance!) ///
296
- var Base1 = /** @class */ ( function ( ) {
297
- function Base1 ( ) {
298
- }
299
- Base1 . prototype . polymorphic = function ( ) { return this . x ; } ;
300
- Base1 . prototype . explicit = function ( ) { return this . x ; } ;
301
- Base1 . explicitStatic = function ( ) { return this . x ; } ;
302
- return Base1 ;
303
- } ( ) ) ;
304
- var Derived1 = /** @class */ ( function ( _super ) {
305
- __extends ( Derived1 , _super ) ;
306
- function Derived1 ( ) {
307
- return _super !== null && _super . apply ( this , arguments ) || this ;
308
- }
309
- return Derived1 ;
310
- } ( Base1 ) ) ;
311
- var Base2 = /** @class */ ( function ( ) {
312
- function Base2 ( ) {
313
- }
314
- Base2 . prototype . polymorphic = function ( ) { return this . y ; } ;
315
- Base2 . prototype . explicit = function ( ) { return this . x ; } ;
316
- return Base2 ;
317
- } ( ) ) ;
318
- var Derived2 = /** @class */ ( function ( _super ) {
319
- __extends ( Derived2 , _super ) ;
320
- function Derived2 ( ) {
321
- return _super !== null && _super . apply ( this , arguments ) || this ;
322
- }
323
- return Derived2 ;
324
- } ( Base2 ) ) ;
325
- var b1 = new Base1 ( ) ;
326
- var d1 = new Derived1 ( ) ;
327
- var b2 = new Base2 ( ) ;
328
- var d2 = new Derived2 ( ) ;
287
+ class Base1 {
288
+ polymorphic ( ) { return this . x ; }
289
+ explicit ( ) { return this . x ; }
290
+ static explicitStatic ( ) { return this . x ; }
291
+ }
292
+ class Derived1 extends Base1 {
293
+ }
294
+ class Base2 {
295
+ polymorphic ( ) { return this . y ; }
296
+ explicit ( ) { return this . x ; }
297
+ }
298
+ class Derived2 extends Base2 {
299
+ }
300
+ let b1 = new Base1 ( ) ;
301
+ let d1 = new Derived1 ( ) ;
302
+ let b2 = new Base2 ( ) ;
303
+ let d2 = new Derived2 ( ) ;
329
304
b1 . polymorphic = b2 . polymorphic ; // error, 'this.y' not in Base1: { x }
330
305
b1 . explicit = b2 . polymorphic ; // error, 'y' not in Base1: { x }
331
306
d1 . explicit = b2 . polymorphic ; // error, 'y' not in Base1: { x }
332
307
////// use this-type for construction with new ////
333
308
function VoidThis ( ) {
334
309
}
335
- var voidThis = new VoidThis ( ) ;
310
+ let voidThis = new VoidThis ( ) ;
336
311
///// syntax-ish errors /////
337
- var ThisConstructor = /** @ class */ ( function ( ) {
338
- function ThisConstructor ( n ) {
312
+ class ThisConstructor {
313
+ constructor ( n ) {
339
314
this . n = n ;
340
315
}
341
- return ThisConstructor ;
342
- } ( ) ) ;
316
+ }
343
317
var thisConstructorType ;
344
318
function notFirst ( a ) { return this . n ; }
345
319
///// parse errors /////
346
320
function modifiers ( ) { return this . n ; }
347
- function restParam ( ) {
348
- var = [ ] ;
349
- for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
350
- [ _i ] = arguments [ _i ] ;
351
- }
352
- return this . n ;
353
- }
321
+ function restParam ( ...) { return this . n ; }
354
322
function optional ( ) { return this . n ; }
355
323
function decorated ( ) { return this . n ; }
356
324
function initializer ( , C ) { }
@@ -360,5 +328,7 @@ number;
360
328
return this . n ;
361
329
}
362
330
// can't name parameters 'this' in a lambda.
363
- c . explicitProperty = ( this , m ) ;
364
- m + this . n ;
331
+ c . explicitProperty = ( m ) => m + this . n ;
332
+ const f2 = ( m ) => m + this . n ;
333
+ const f3 = ( m ) => __awaiter ( this , void 0 , void 0 , function * ( ) { return m + this . n ; } ) ;
334
+ const f4 = ( m ) => __awaiter ( this , void 0 , void 0 , function * ( ) { return m + this . n ; } ) ;
0 commit comments