From bf19d214f32e2a30eced6b896ccc10fff01ec264 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 6 Aug 2018 16:10:10 -0700 Subject: [PATCH] Revise logic that computes the contextual type for a parameter --- src/compiler/checker.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de0da714fcf..130086ca9a2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15820,20 +15820,10 @@ namespace ts { } const contextualSignature = getContextualSignature(func); if (contextualSignature) { - const funcHasRestParameter = hasRestParameter(func); - const len = func.parameters.length - (funcHasRestParameter ? 1 : 0); - let indexOfParameter = func.parameters.indexOf(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); - } - // If last parameter is contextually rest parameter get its type - if (funcHasRestParameter && indexOfParameter === len) { - return getRestTypeAtPosition(contextualSignature, indexOfParameter); - } + const index = func.parameters.indexOf(parameter) - (getThisParameter(func) ? 1 : 0); + return parameter.dotDotDotToken && lastOrUndefined(func.parameters) === parameter ? + getRestTypeAtPosition(contextualSignature, index) : + tryGetTypeAtPosition(contextualSignature, index); } }