2016-01-29 23:49:52 +01:00
|
|
|
interface I {
|
2016-02-05 00:43:43 +01:00
|
|
|
n: number;
|
2016-01-29 23:49:52 +01:00
|
|
|
explicitThis(this: this, m: number): number;
|
|
|
|
}
|
|
|
|
interface Unused {
|
|
|
|
implicitNoThis(m: number): number;
|
|
|
|
}
|
|
|
|
class C implements I {
|
|
|
|
n: number;
|
|
|
|
explicitThis(this: this, m: number): number {
|
|
|
|
return this.n + m;
|
|
|
|
}
|
|
|
|
implicitThis(m: number): number {
|
|
|
|
return this.n + m;
|
|
|
|
}
|
|
|
|
explicitVoid(this: void, m: number): number {
|
|
|
|
return m + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let c = new C();
|
|
|
|
c.explicitVoid = c.explicitThis; // error, 'void' is missing everything
|
2016-04-29 19:31:01 +02:00
|
|
|
let o = {
|
2016-02-05 00:43:43 +01:00
|
|
|
n: 101,
|
2016-04-29 19:31:01 +02:00
|
|
|
explicitThis: function (m: number) {
|
|
|
|
return m + this.n.length; // error, 'length' does not exist on 'number'
|
2016-02-05 00:43:43 +01:00
|
|
|
},
|
2016-04-29 19:31:01 +02:00
|
|
|
implicitThis(m: number): number { return m; }
|
2016-01-29 23:49:52 +01:00
|
|
|
};
|
|
|
|
let i: I = o;
|
2016-02-05 00:43:43 +01:00
|
|
|
let o2: I = {
|
2016-02-09 01:39:19 +01:00
|
|
|
n: 1001,
|
2016-02-05 00:43:43 +01:00
|
|
|
explicitThis: function (m) {
|
2016-02-09 01:39:19 +01:00
|
|
|
return m + this.n.length; // error, this.n: number, no member 'length'
|
2016-02-05 00:43:43 +01:00
|
|
|
},
|
|
|
|
}
|
2016-01-29 23:49:52 +01:00
|
|
|
let x = i.explicitThis;
|
|
|
|
let n = x(12); // callee:void doesn't match this:I
|
|
|
|
let u: Unused;
|
|
|
|
let y = u.implicitNoThis;
|
|
|
|
n = y(12); // ok, callee:void matches this:any
|
|
|
|
c.explicitVoid = c.implicitThis // ok, implicitThis(this:any)
|
|
|
|
o.implicitThis = c.implicitThis; // ok, implicitThis(this:any)
|
|
|
|
o.implicitThis = c.explicitThis; // ok, implicitThis(this:any) is assignable to explicitThis(this: this)
|
|
|
|
o.implicitThis = i.explicitThis;
|
2016-02-05 00:43:43 +01:00
|
|
|
i.explicitThis = function(m) {
|
2016-02-09 01:39:19 +01:00
|
|
|
return this.n.length; // error, this.n: number
|
2016-04-29 19:31:01 +02:00
|
|
|
}
|