@@ -174,69 +174,60 @@ function initializer(this: C = new C()): number { return this.n; }
174174
175175// can't name parameters 'this' in a lambda.
176176c . 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 ;
177180
178181
179182//// [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 ) {
198193 return this . n + m ;
199- } ;
200- C . prototype . implicitThis = function ( m ) {
194+ }
195+ implicitThis ( m ) {
201196 return this . n + m ;
202- } ;
203- C . prototype . explicitC = function ( m ) {
197+ }
198+ explicitC ( m ) {
204199 return this . n + m ;
205- } ;
206- C . prototype . explicitProperty = function ( m ) {
200+ }
201+ explicitProperty ( m ) {
207202 return this . n + m ;
208- } ;
209- C . prototype . explicitVoid = function ( m ) {
203+ }
204+ explicitVoid ( m ) {
210205 return this . n + m ; // 'n' doesn't exist on type 'void'.
211- } ;
212- return C ;
213- } ( ) ) ;
214- var D = /** @class */ ( function ( ) {
215- function D ( ) {
216206 }
217- D . prototype . explicitThis = function ( m ) {
207+ }
208+ class D {
209+ explicitThis ( m ) {
218210 return this . x + m ;
219- } ;
220- D . prototype . explicitD = function ( m ) {
211+ }
212+ explicitD ( m ) {
221213 return this . x + m ;
222- } ;
223- return D ;
224- } ( ) ) ;
225- var impl = {
214+ }
215+ }
216+ let impl = {
226217 a : 12 ,
227- explicitVoid1 : function ( ) {
218+ explicitVoid1 ( ) {
228219 return this . a ; // error, no 'a' in 'void'
229220 } ,
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 ( ) {
234225 return this . a ;
235- }
226+ } ,
236227} ;
237- var implExplicitStructural = impl . explicitStructural ;
228+ let implExplicitStructural = impl . explicitStructural ;
238229implExplicitStructural ( ) ; // error, no 'a' in 'void'
239- var implExplicitInterface = impl . explicitInterface ;
230+ let implExplicitInterface = impl . explicitInterface ;
240231implExplicitInterface ( ) ; // error, no 'a' in 'void'
241232function explicitStructural ( x ) {
242233 return x + this . y ;
@@ -247,15 +238,15 @@ function propertyName(x) {
247238function voidThisSpecified ( x ) {
248239 return x + this . notSpecified ;
249240}
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 } ;
253244ok . f ( ) ; // not enough arguments
254245ok . f ( 'wrong type' ) ;
255246ok . f ( 13 , 'too many arguments' ) ;
256247wrongPropertyType . f ( 13 ) ;
257248wrongPropertyName . f ( 13 ) ;
258- var c = new C ( ) ;
249+ let c = new C ( ) ;
259250c . explicitC ( ) ; // not enough arguments
260251c . explicitC ( 'wrong type' ) ;
261252c . explicitC ( 13 , 'too many arguments' ) ;
@@ -269,8 +260,8 @@ c.explicitProperty(); // not enough arguments
269260c . explicitProperty ( 'wrong type 3' ) ;
270261c . explicitProperty ( 15 , 'too many arguments 3' ) ;
271262// 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 = {
274265 n : 12 ,
275266 explicitThis : c . explicitThis ,
276267 explicitC : c . explicitC ,
@@ -279,8 +270,8 @@ var reconstructed = {
279270} ;
280271;
281272// 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 ;
284275// from differing object types
285276c . explicitC = function ( m ) { return this . x + m ; } ;
286277c . explicitProperty = explicitXProperty ;
@@ -293,64 +284,41 @@ c.explicitThis = d.explicitThis;
293284c . explicitVoid = d . explicitD ;
294285c . explicitVoid = d . explicitThis ;
295286/// 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 ( ) ;
329304b1 . polymorphic = b2 . polymorphic ; // error, 'this.y' not in Base1: { x }
330305b1 . explicit = b2 . polymorphic ; // error, 'y' not in Base1: { x }
331306d1 . explicit = b2 . polymorphic ; // error, 'y' not in Base1: { x }
332307////// use this-type for construction with new ////
333308function VoidThis ( ) {
334309}
335- var voidThis = new VoidThis ( ) ;
310+ let voidThis = new VoidThis ( ) ;
336311///// syntax-ish errors /////
337- var ThisConstructor = /** @ class */ ( function ( ) {
338- function ThisConstructor ( n ) {
312+ class ThisConstructor {
313+ constructor ( n ) {
339314 this . n = n ;
340315 }
341- return ThisConstructor ;
342- } ( ) ) ;
316+ }
343317var thisConstructorType ;
344318function notFirst ( a ) { return this . n ; }
345319///// parse errors /////
346320function 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 ; }
354322function optional ( ) { return this . n ; }
355323function decorated ( ) { return this . n ; }
356324function initializer ( , C ) { }
@@ -360,5 +328,7 @@ number;
360328 return this . n ;
361329}
362330// 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