diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 645b3835b9307..d61cde014518c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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)) { if (type === target) { return true; } diff --git a/tests/baselines/reference/thisTypeAsConstraint.js b/tests/baselines/reference/thisTypeAsConstraint.js new file mode 100644 index 0000000000000..b5a7113549dba --- /dev/null +++ b/tests/baselines/reference/thisTypeAsConstraint.js @@ -0,0 +1,14 @@ +//// [thisTypeAsConstraint.ts] +class C { + public m() { + } +} + +//// [thisTypeAsConstraint.js] +var C = (function () { + function C() { + } + C.prototype.m = function () { + }; + return C; +}()); diff --git a/tests/baselines/reference/thisTypeAsConstraint.symbols b/tests/baselines/reference/thisTypeAsConstraint.symbols new file mode 100644 index 0000000000000..020dd966cad19 --- /dev/null +++ b/tests/baselines/reference/thisTypeAsConstraint.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/thisTypeAsConstraint.ts === +class C { +>C : Symbol(C, Decl(thisTypeAsConstraint.ts, 0, 0)) + + public m() { +>m : Symbol(m, Decl(thisTypeAsConstraint.ts, 0, 9)) +>T : Symbol(T, Decl(thisTypeAsConstraint.ts, 1, 11)) + } +} diff --git a/tests/baselines/reference/thisTypeAsConstraint.types b/tests/baselines/reference/thisTypeAsConstraint.types new file mode 100644 index 0000000000000..e55fb1f0cca67 --- /dev/null +++ b/tests/baselines/reference/thisTypeAsConstraint.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/thisTypeAsConstraint.ts === +class C { +>C : C + + public m() { +>m : () => void +>T : T + } +} diff --git a/tests/cases/compiler/thisTypeAsConstraint.ts b/tests/cases/compiler/thisTypeAsConstraint.ts new file mode 100644 index 0000000000000..fcab82bc7ccf2 --- /dev/null +++ b/tests/cases/compiler/thisTypeAsConstraint.ts @@ -0,0 +1,4 @@ +class C { + public m() { + } +} \ No newline at end of file