diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 30a0bbd2042c8..2aac2d681bc96 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4776,9 +4776,6 @@ namespace ts { if (isJSConstructSignature) { minArgumentCount--; } - if (!thisParameter && isObjectLiteralMethod(declaration)) { - thisParameter = getContextualThisParameter(declaration); - } const classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent).symbol)) @@ -9429,8 +9426,13 @@ namespace ts { return getInferredClassType(classSymbol); } } + let thisType = getThisTypeOfDeclaration(container); + if (thisType) { + return thisType; + } - const thisType = getThisTypeOfDeclaration(container); + const thisParameter = getContextualThisParameter(container); + thisType = thisParameter && getTypeOfSymbol(thisParameter); if (thisType) { return thisType; } diff --git a/tests/cases/fourslash/memberListOnContextualThis.ts b/tests/cases/fourslash/memberListOnContextualThis.ts new file mode 100644 index 0000000000000..7eeb67dc62046 --- /dev/null +++ b/tests/cases/fourslash/memberListOnContextualThis.ts @@ -0,0 +1,12 @@ +/// +////interface A { +//// a: string; +////} +////declare function ctx(callback: (this: A) => string): string; +////ctx(function () { return th/*1*/is./*2*/a }); + +goTo.marker('1'); +verify.quickInfoIs("this: A"); +goTo.marker('2'); +verify.memberListContains('a', '(property) A.a: string'); +