Skip to content

Commit bf19d21

Browse files
committed
Revise logic that computes the contextual type for a parameter
1 parent d0ed21c commit bf19d21

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15820,20 +15820,10 @@ namespace ts {
1582015820
}
1582115821
const contextualSignature = getContextualSignature(func);
1582215822
if (contextualSignature) {
15823-
const funcHasRestParameter = hasRestParameter(func);
15824-
const len = func.parameters.length - (funcHasRestParameter ? 1 : 0);
15825-
let indexOfParameter = func.parameters.indexOf(parameter);
15826-
if (getThisParameter(func) !== undefined && !contextualSignature.thisParameter) {
15827-
Debug.assert(indexOfParameter !== 0); // Otherwise we should not have called `getContextuallyTypedParameterType`.
15828-
indexOfParameter -= 1;
15829-
}
15830-
if (indexOfParameter < len) {
15831-
return getTypeAtPosition(contextualSignature, indexOfParameter);
15832-
}
15833-
// If last parameter is contextually rest parameter get its type
15834-
if (funcHasRestParameter && indexOfParameter === len) {
15835-
return getRestTypeAtPosition(contextualSignature, indexOfParameter);
15836-
}
15823+
const index = func.parameters.indexOf(parameter) - (getThisParameter(func) ? 1 : 0);
15824+
return parameter.dotDotDotToken && lastOrUndefined(func.parameters) === parameter ?
15825+
getRestTypeAtPosition(contextualSignature, index) :
15826+
tryGetTypeAtPosition(contextualSignature, index);
1583715827
}
1583815828
}
1583915829

0 commit comments

Comments
 (0)