forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request microsoft#19655 from Microsoft/instantiate-this-in…
…-type-parameter-constraints Instantiate this when used only in type parameter constraints
- Loading branch information
Showing
5 changed files
with
144 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
tests/cases/conformance/types/thisType/thisTypeInFunctions3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare class Base { | ||
check<TProp extends this>(prop: TProp): boolean; | ||
} | ||
|
||
class Test extends Base { | ||
m() { | ||
this.check(this); | ||
} | ||
} |