Skip to content

Give correct info for contextually typed this #11600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 6 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4776,9 +4776,6 @@ namespace ts {
if (isJSConstructSignature) {
minArgumentCount--;
}
if (!thisParameter && isObjectLiteralMethod(declaration)) {
thisParameter = getContextualThisParameter(declaration);
}

const classType = declaration.kind === SyntaxKind.Constructor ?
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol))
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/fourslash/memberListOnContextualThis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path='fourslash.ts'/>
////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');