From 31331ff6d1399acf51ec68edef0d6052a468b255 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 5 Nov 2015 16:31:30 -0800 Subject: [PATCH] Addressing CR feedback --- src/compiler/checker.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1fde2711e12..836c16b51d8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5603,28 +5603,30 @@ namespace ts { return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } - // A source signature matches a target signature if the two signatures have the same number of required, - // optional, and rest parameters. - function isMatchingSignature(source: Signature, target: Signature) { - return source.parameters.length === target.parameters.length && + function isMatchingSignature(source: Signature, target: Signature, partialMatch: boolean) { + // A source signature matches a target signature if the two signatures have the same number of required, + // optional, and rest parameters. + if (source.parameters.length === target.parameters.length && source.minArgumentCount === target.minArgumentCount && - source.hasRestParameter === target.hasRestParameter; - } - - // A source signature partially matches a target signature if the target signature has no fewer required - // parameters and no more overall parameters than the source signature (where a signature with a rest - // parameter is always considered to have more overall parameters than one without). - function isPartiallyMatchingSignature(source: Signature, target: Signature) { - return source.minArgumentCount <= target.minArgumentCount && ( + source.hasRestParameter === target.hasRestParameter) { + return true; + } + // A source signature partially matches a target signature if the target signature has no fewer required + // parameters and no more overall parameters than the source signature (where a signature with a rest + // parameter is always considered to have more overall parameters than one without). + if (partialMatch && source.minArgumentCount <= target.minArgumentCount && ( source.hasRestParameter && !target.hasRestParameter || - source.hasRestParameter === target.hasRestParameter && source.parameters.length >= target.parameters.length); + source.hasRestParameter === target.hasRestParameter && source.parameters.length >= target.parameters.length)) { + return true; + } + return false; } function compareSignatures(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary { if (source === target) { return Ternary.True; } - if (!(isMatchingSignature(source, target) || partialMatch && isPartiallyMatchingSignature(source, target))) { + if (!(isMatchingSignature(source, target, partialMatch))) { return Ternary.False; } let result = Ternary.True;