Skip to content

In getContextuallyTypedParameterType, skip a this parameter when counting parameter index #19155

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

Merged
1 commit merged into from
Oct 13, 2017
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
9 changes: 7 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13182,7 +13182,7 @@ namespace ts {
}

// Return contextual type of parameter or undefined if no contextual type is available
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type | undefined {
const func = parameter.parent;
if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
const iife = getImmediatelyInvokedFunctionExpression(func);
Expand All @@ -13208,7 +13208,12 @@ namespace ts {
if (contextualSignature) {
const funcHasRestParameters = hasRestParameter(func);
const len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
const indexOfParameter = indexOf(func.parameters, parameter);
let indexOfParameter = indexOf(func.parameters, parameter);
if (getThisParameter(func) !== undefined && !contextualSignature.thisParameter) {
Debug.assert(indexOfParameter !== 0); // Otherwise we should not have called `getContextuallyTypedParameterType`.
indexOfParameter -= 1;
}

if (indexOfParameter < len) {
return getTypeAtPosition(contextualSignature, indexOfParameter);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/fourslash/quickInfoParameter_skipThisParameter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference path='fourslash.ts'/>

////function f(cb: (x: number) => void) {}
////f(function(this: any, /**/x) {});

verify.quickInfoAt("", "(parameter) x: number");