Split error messages so they are localisable

This commit is contained in:
Nathan Shively-Sanders
2017-05-16 08:05:07 -07:00
parent c9308fc610
commit 381f056c68
2 changed files with 24 additions and 7 deletions

View File

@@ -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);

View File

@@ -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