Test:this instantiation in type parameters

Make sure that `this` gets instantiated when it's used as a constraint
of a type parameter, and nowhere else in a signature.
This commit is contained in:
Nathan Shively-Sanders 2017-11-01 09:17:52 -07:00
parent db88c8eac2
commit e0e1a3b078
4 changed files with 95 additions and 0 deletions

View file

@ -0,0 +1,33 @@
//// [thisTypeInFunctions3.ts]
declare class Base {
check<TProp extends this>(prop: TProp): boolean;
}
class Test extends Base {
m() {
this.check(this);
}
}
//// [thisTypeInFunctions3.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Test = /** @class */ (function (_super) {
__extends(Test, _super);
function Test() {
return _super !== null && _super.apply(this, arguments) || this;
}
Test.prototype.m = function () {
this.check(this);
};
return Test;
}(Base));

View file

@ -0,0 +1,26 @@
=== tests/cases/conformance/types/thisType/thisTypeInFunctions3.ts ===
declare class Base {
>Base : Symbol(Base, Decl(thisTypeInFunctions3.ts, 0, 0))
check<TProp extends this>(prop: TProp): boolean;
>check : Symbol(Base.check, Decl(thisTypeInFunctions3.ts, 0, 20))
>TProp : Symbol(TProp, Decl(thisTypeInFunctions3.ts, 1, 10))
>prop : Symbol(prop, Decl(thisTypeInFunctions3.ts, 1, 30))
>TProp : Symbol(TProp, Decl(thisTypeInFunctions3.ts, 1, 10))
}
class Test extends Base {
>Test : Symbol(Test, Decl(thisTypeInFunctions3.ts, 2, 1))
>Base : Symbol(Base, Decl(thisTypeInFunctions3.ts, 0, 0))
m() {
>m : Symbol(Test.m, Decl(thisTypeInFunctions3.ts, 4, 25))
this.check(this);
>this.check : Symbol(Base.check, Decl(thisTypeInFunctions3.ts, 0, 20))
>this : Symbol(Test, Decl(thisTypeInFunctions3.ts, 2, 1))
>check : Symbol(Base.check, Decl(thisTypeInFunctions3.ts, 0, 20))
>this : Symbol(Test, Decl(thisTypeInFunctions3.ts, 2, 1))
}
}

View file

@ -0,0 +1,27 @@
=== tests/cases/conformance/types/thisType/thisTypeInFunctions3.ts ===
declare class Base {
>Base : Base
check<TProp extends this>(prop: TProp): boolean;
>check : <TProp extends this>(prop: TProp) => boolean
>TProp : TProp
>prop : TProp
>TProp : TProp
}
class Test extends Base {
>Test : Test
>Base : Base
m() {
>m : () => void
this.check(this);
>this.check(this) : boolean
>this.check : <TProp extends this>(prop: TProp) => boolean
>this : this
>check : <TProp extends this>(prop: TProp) => boolean
>this : this
}
}

View file

@ -0,0 +1,9 @@
declare class Base {
check<TProp extends this>(prop: TProp): boolean;
}
class Test extends Base {
m() {
this.check(this);
}
}