diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e7e871f12b3..73147bb99bb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15380,19 +15380,24 @@ namespace ts { reportError(Diagnostics.Expected_0_type_arguments_but_got_1, paramMessage, typeArguments.length.toString()); } else if (args) { - const argMessage = getSpreadArgumentIndex(args) > -1 ? - "a minimum of " + (args.length - 1) : - args.length.toString(); let min = Number.POSITIVE_INFINITY; let max = Number.NEGATIVE_INFINITY; for (const sig of signatures) { min = Math.min(min, sig.minArgumentCount); max = Math.max(max, sig.parameters.length); } - const paramMessage = some(signatures, sig => sig.hasRestParameter) ? "at least " + min : + /////////// + const hasRestParameter = some(signatures, sig => sig.hasRestParameter); + const hasSpreadArgument = getSpreadArgumentIndex(args) > -1; + const paramCount = hasRestParameter ? min : min < max ? `${min}-${max}` : - min.toString(); - reportError(Diagnostics.Expected_0_arguments_but_got_1, paramMessage, argMessage); + min; + const argCount = args.length - (hasSpreadArgument ? 1 : 0); + const error = hasRestParameter && hasSpreadArgument ? Diagnostics.Expected_at_least_0_arguments_but_got_a_minimum_of_1 : + hasRestParameter ? Diagnostics.Expected_at_least_0_arguments_but_got_1 : + hasSpreadArgument ? Diagnostics.Expected_0_arguments_but_got_a_minimum_of_1 : + Diagnostics.Expected_0_arguments_but_got_1; + reportError(error, paramCount.toString(), argCount.toString()); } else { reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 849b780380f..0f4d373c05b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1859,10 +1859,22 @@ "category": "Error", "code": 2553 }, - "Expected {0} type arguments, but got {1}.": { + "Expected at least {0} arguments, but got {1}.": { "category": "Error", "code": 2554 }, + "Expected {0} arguments, but got a minimum of {1}.": { + "category": "Error", + "code": 2555 + }, + "Expected at least {0} arguments, but got a minimum of {1}.": { + "category": "Error", + "code": 2556 + }, + "Expected {0} type arguments, but got {1}.": { + "category": "Error", + "code": 2557 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600