@@ -8,9 +8,6 @@ class C {
88 explicitThis ( this : this , m : number ) : number {
99 return this . n + m ;
1010 }
11- implicitThis ( m : number ) : number {
12- return this . n + m ;
13- }
1411 explicitC ( this : C , m : number ) : number {
1512 return this . n + m ;
1613 }
@@ -29,8 +26,6 @@ interface I {
2926 explicitStructural ( this : { a : number } ) : number ;
3027 explicitInterface ( this : I ) : number ;
3128 explicitThis ( this : this ) : number ;
32- implicitMethod ( ) : number ;
33- implicitFunction : ( ) = > number ;
3429}
3530function explicitStructural ( this : { y : number } , x : number ) : number {
3631 return x + this . y ;
@@ -39,7 +34,7 @@ function justThis(this: { y: number }): number {
3934 return this . y ;
4035}
4136function implicitThis ( n : number ) : number {
42- return 12 ;
37+ return this . m + n + 12 ;
4338}
4439let impl : I = {
4540 a : 12 ,
@@ -54,10 +49,6 @@ let impl: I = {
5449 explicitThis ( ) {
5550 return this . a ;
5651 } ,
57- implicitMethod ( ) {
58- return this . a ;
59- } ,
60- implicitFunction : ( ) => this . a , // ok, this: any because it refers to some outer object (window?)
6152}
6253impl . explicitVoid1 = function ( ) { return 12 ; } ;
6354impl . explicitVoid2 = ( ) => 12 ;
@@ -66,9 +57,6 @@ impl.explicitInterface = function() { return this.a; };
6657impl . explicitStructural = ( ) => 12 ;
6758impl . explicitInterface = ( ) => 12 ;
6859impl . explicitThis = function ( ) { return this . a ; } ;
69- impl . implicitMethod = function ( ) { return this . a ; } ;
70- impl . implicitMethod = ( ) => 12 ;
71- impl . implicitFunction = ( ) => this . a ; // ok, this: any because it refers to some outer object (window?)
7260// parameter checking
7361let ok : { y : number , f : ( this : { y : number } , x : number ) = > number } = { y : 12 , f : explicitStructural } ;
7462let implicitAnyOk : { notSpecified : number , f : ( x : number ) = > number } = { notSpecified : 12 , f : implicitThis } ;
@@ -82,29 +70,26 @@ let ripped = c.explicitC;
8270c . explicitC ( 12 ) ;
8371c . explicitProperty ( 12 ) ;
8472c . explicitThis ( 12 ) ;
85- c . implicitThis ( 12 ) ;
8673d . explicitC ( 12 ) ;
8774d . explicitProperty ( 12 ) ;
8875d . explicitThis ( 12 ) ;
89- d . implicitThis ( 12 ) ;
9076let reconstructed : {
9177 n : number ,
9278 explicitThis ( this : C , m : number ) : number , // note: this: this is not allowed in an object literal type.
93- implicitThis ( m : number ) : number ,
9479 explicitC ( this : C , m : number ) : number ,
9580 explicitProperty : ( this : { n : number } , m : number ) = > number ,
9681 explicitVoid ( this : void , m : number ) : number ,
9782} = {
9883 n : 12 ,
9984 explicitThis : c . explicitThis ,
100- implicitThis : c . implicitThis ,
10185 explicitC : c . explicitC ,
10286 explicitProperty : c . explicitProperty ,
10387 explicitVoid : c . explicitVoid
10488} ;
89+ reconstructed . explicitThis ( 10 ) ;
10590reconstructed . explicitProperty ( 11 ) ;
106- reconstructed . implicitThis ( 11 ) ;
107-
91+ let explicitVoid = reconstructed . explicitVoid ;
92+ explicitVoid ( 12 ) ;
10893// assignment checking
10994let unboundToSpecified : ( this : { y : number } , x : number ) = > number = x => x + this . y ; // ok, this:any
11095let specifiedToSpecified : ( this : { y : number } , x : number ) = > number = explicitStructural ;
@@ -143,8 +128,6 @@ c.explicitThis = function(this: C, m: number) { return this.n + m };
143128c . explicitC = function ( m ) { return this . n + m } ;
144129c . explicitProperty = function ( m ) { return this . n + m } ;
145130c . explicitThis = function ( m ) { return this . n + m } ;
146- c . implicitThis = function ( m ) { return this . n + m } ;
147- c . implicitThis = reconstructed . implicitThis ;
148131
149132c . explicitC = function ( this : B , m : number ) { return this . n + m } ;
150133
@@ -154,19 +137,17 @@ c.explicitVoid = n => n;
154137// class-based assignability
155138class Base1 {
156139 x : number ;
157- public implicit ( ) : number { return this . x ; }
140+ public polymorphic ( this : this ) : number { return this . x ; }
158141 explicit ( this : Base1 ) : number { return this . x ; }
159- static implicitStatic ( ) : number { return this . y ; }
160142 static explicitStatic ( this : typeof Base1 ) : number { return this . y ; }
161143 static y : number ;
162-
163144}
164145class Derived1 extends Base1 {
165146 y : number
166147}
167148class Base2 {
168149 y : number
169- implicit ( ) : number { return this . y ; }
150+ polymorphic ( this : this ) : number { return this . y ; }
170151 explicit ( this : Base1 ) : number { return this . x ; }
171152}
172153class Derived2 extends Base2 {
@@ -176,14 +157,14 @@ let b1 = new Base1();
176157let b2 = new Base2 ( ) ;
177158let d1 = new Derived1 ( ) ;
178159let d2 = new Derived2 ( ) ;
179- d2 . implicit = d1 . implicit // ok, 'x' and 'y' in { x, y } (d assignable to f and vice versa)
180- d1 . implicit = d2 . implicit // ok, 'x' and 'y' in { x, y } (f assignable to d and vice versa)
160+ d2 . polymorphic = d1 . polymorphic // ok, 'x' and 'y' in { x, y }
161+ d1 . polymorphic = d2 . polymorphic // ok, 'x' and 'y' in { x, y }
181162
182163// bivariance-allowed cases
183- d1 . implicit = b2 . implicit // ok, 'y' in D: { x, y } (d assignable e)
184- d2 . implicit = d1 . explicit // ok, 'y' in { x, y } (c assignable to f)
185- b1 . implicit = d2 . implicit // ok, 'x' and 'y' not in C : { x } (c assignable to f)
186- b1 . explicit = d2 . implicit // ok, 'x' and 'y' not in C : { x } (c assignable to f)
164+ d1 . polymorphic = b2 . polymorphic // ok, 'y' in D: { x, y }
165+ d2 . polymorphic = d1 . explicit // ok, 'y' in { x, y }
166+ b1 . polymorphic = d2 . polymorphic // ok, 'x' and 'y' not in Base1 : { x }
167+ b1 . explicit = d2 . polymorphic // ok, 'x' and 'y' not in Base1 : { x }
187168
188169////// use this-type for construction with new ////
189170function InterfaceThis ( this : I ) {
@@ -206,7 +187,7 @@ declare var f: {
206187} ;
207188let n : number = f . call ( 12 ) ;
208189
209- function missingTypeIsImplicitAny ( this , a : number ) { return a ; }
190+ function missingTypeIsImplicitAny ( this , a : number ) { return this . anything + a ; }
210191
211192
212193//// [thisTypeInFunctions.js]
@@ -228,9 +209,6 @@ var C = (function () {
228209 C . prototype . explicitThis = function ( m ) {
229210 return this . n + m ;
230211 } ;
231- C . prototype . implicitThis = function ( m ) {
232- return this . n + m ;
233- } ;
234212 C . prototype . explicitC = function ( m ) {
235213 return this . n + m ;
236214 } ;
@@ -256,7 +234,7 @@ function justThis() {
256234 return this . y ;
257235}
258236function implicitThis ( n ) {
259- return 12 ;
237+ return this . m + n + 12 ;
260238}
261239var impl = {
262240 a : 12 ,
@@ -270,11 +248,7 @@ var impl = {
270248 } ,
271249 explicitThis : function ( ) {
272250 return this . a ;
273- } ,
274- implicitMethod : function ( ) {
275- return this . a ;
276- } ,
277- implicitFunction : function ( ) { return _this . a ; }
251+ }
278252} ;
279253impl . explicitVoid1 = function ( ) { return 12 ; } ;
280254impl . explicitVoid2 = function ( ) { return 12 ; } ;
@@ -283,9 +257,6 @@ impl.explicitInterface = function () { return this.a; };
283257impl . explicitStructural = function ( ) { return 12 ; } ;
284258impl . explicitInterface = function ( ) { return 12 ; } ;
285259impl . explicitThis = function ( ) { return this . a ; } ;
286- impl . implicitMethod = function ( ) { return this . a ; } ;
287- impl . implicitMethod = function ( ) { return 12 ; } ;
288- impl . implicitFunction = function ( ) { return _this . a ; } ; // ok, this: any because it refers to some outer object (window?)
289260// parameter checking
290261var ok = { y : 12 , f : explicitStructural } ;
291262var implicitAnyOk = { notSpecified : 12 , f : implicitThis } ;
@@ -298,21 +269,20 @@ var ripped = c.explicitC;
298269c . explicitC ( 12 ) ;
299270c . explicitProperty ( 12 ) ;
300271c . explicitThis ( 12 ) ;
301- c . implicitThis ( 12 ) ;
302272d . explicitC ( 12 ) ;
303273d . explicitProperty ( 12 ) ;
304274d . explicitThis ( 12 ) ;
305- d . implicitThis ( 12 ) ;
306275var reconstructed = {
307276 n : 12 ,
308277 explicitThis : c . explicitThis ,
309- implicitThis : c . implicitThis ,
310278 explicitC : c . explicitC ,
311279 explicitProperty : c . explicitProperty ,
312280 explicitVoid : c . explicitVoid
313281} ;
282+ reconstructed . explicitThis ( 10 ) ;
314283reconstructed . explicitProperty ( 11 ) ;
315- reconstructed . implicitThis ( 11 ) ;
284+ var explicitVoid = reconstructed . explicitVoid ;
285+ explicitVoid ( 12 ) ;
316286// assignment checking
317287var unboundToSpecified = function ( x ) { return x + _this . y ; } ; // ok, this:any
318288var specifiedToSpecified = explicitStructural ;
@@ -344,18 +314,15 @@ c.explicitThis = function (m) { return this.n + m; };
344314c . explicitC = function ( m ) { return this . n + m ; } ;
345315c . explicitProperty = function ( m ) { return this . n + m ; } ;
346316c . explicitThis = function ( m ) { return this . n + m ; } ;
347- c . implicitThis = function ( m ) { return this . n + m ; } ;
348- c . implicitThis = reconstructed . implicitThis ;
349317c . explicitC = function ( m ) { return this . n + m ; } ;
350318// this:void compatibility
351319c . explicitVoid = function ( n ) { return n ; } ;
352320// class-based assignability
353321var Base1 = ( function ( ) {
354322 function Base1 ( ) {
355323 }
356- Base1 . prototype . implicit = function ( ) { return this . x ; } ;
324+ Base1 . prototype . polymorphic = function ( ) { return this . x ; } ;
357325 Base1 . prototype . explicit = function ( ) { return this . x ; } ;
358- Base1 . implicitStatic = function ( ) { return this . y ; } ;
359326 Base1 . explicitStatic = function ( ) { return this . y ; } ;
360327 return Base1 ;
361328} ( ) ) ;
@@ -369,7 +336,7 @@ var Derived1 = (function (_super) {
369336var Base2 = ( function ( ) {
370337 function Base2 ( ) {
371338 }
372- Base2 . prototype . implicit = function ( ) { return this . y ; } ;
339+ Base2 . prototype . polymorphic = function ( ) { return this . y ; } ;
373340 Base2 . prototype . explicit = function ( ) { return this . x ; } ;
374341 return Base2 ;
375342} ( ) ) ;
@@ -384,13 +351,13 @@ var b1 = new Base1();
384351var b2 = new Base2 ( ) ;
385352var d1 = new Derived1 ( ) ;
386353var d2 = new Derived2 ( ) ;
387- d2 . implicit = d1 . implicit ; // ok, 'x' and 'y' in { x, y } (d assignable to f and vice versa)
388- d1 . implicit = d2 . implicit ; // ok, 'x' and 'y' in { x, y } (f assignable to d and vice versa)
354+ d2 . polymorphic = d1 . polymorphic ; // ok, 'x' and 'y' in { x, y }
355+ d1 . polymorphic = d2 . polymorphic ; // ok, 'x' and 'y' in { x, y }
389356// bivariance-allowed cases
390- d1 . implicit = b2 . implicit ; // ok, 'y' in D: { x, y } (d assignable e)
391- d2 . implicit = d1 . explicit ; // ok, 'y' in { x, y } (c assignable to f)
392- b1 . implicit = d2 . implicit ; // ok, 'x' and 'y' not in C : { x } (c assignable to f)
393- b1 . explicit = d2 . implicit ; // ok, 'x' and 'y' not in C : { x } (c assignable to f)
357+ d1 . polymorphic = b2 . polymorphic ; // ok, 'y' in D: { x, y }
358+ d2 . polymorphic = d1 . explicit ; // ok, 'y' in { x, y }
359+ b1 . polymorphic = d2 . polymorphic ; // ok, 'x' and 'y' not in Base1 : { x }
360+ b1 . explicit = d2 . polymorphic ; // ok, 'x' and 'y' not in Base1 : { x }
394361////// use this-type for construction with new ////
395362function InterfaceThis ( ) {
396363 this . a = 12 ;
@@ -405,4 +372,4 @@ var interfaceThis = new InterfaceThis();
405372var literalTypeThis = new LiteralTypeThis ( ) ;
406373var anyThis = new AnyThis ( ) ;
407374var n = f . call ( 12 ) ;
408- function missingTypeIsImplicitAny ( a ) { return a ; }
375+ function missingTypeIsImplicitAny ( a ) { return this . anything + a ; }
0 commit comments