Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4285,7 +4285,7 @@ namespace ts {

function hasConstraintReferenceTo(type: Type, target: TypeParameter): boolean {
let checked: Type[];
while (type && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) {
while (type && !(type.flags & TypeFlags.ThisType) && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather you move the new check into the body and break with a comment explaining why you need to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the check is fine here with all the other checks.

if (type === target) {
return true;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/thisTypeAsConstraint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [thisTypeAsConstraint.ts]
class C {
public m<T extends this>() {
}
}

//// [thisTypeAsConstraint.js]
var C = (function () {
function C() {
}
C.prototype.m = function () {
};
return C;
}());
9 changes: 9 additions & 0 deletions tests/baselines/reference/thisTypeAsConstraint.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/compiler/thisTypeAsConstraint.ts ===
class C {
>C : Symbol(C, Decl(thisTypeAsConstraint.ts, 0, 0))

public m<T extends this>() {
>m : Symbol(m, Decl(thisTypeAsConstraint.ts, 0, 9))
>T : Symbol(T, Decl(thisTypeAsConstraint.ts, 1, 11))
}
}
9 changes: 9 additions & 0 deletions tests/baselines/reference/thisTypeAsConstraint.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/compiler/thisTypeAsConstraint.ts ===
class C {
>C : C

public m<T extends this>() {
>m : <T extends this>() => void
>T : T
}
}
4 changes: 4 additions & 0 deletions tests/cases/compiler/thisTypeAsConstraint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class C {
public m<T extends this>() {
}
}