mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Improve arity error messages
For calls with one signature.
This commit is contained in:
parent
278fb803b1
commit
93b1eafb9f
@ -15370,7 +15370,27 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
|
||||
if (signatures.length === 1) {
|
||||
if (typeArguments && typeArguments.length !== length(signatures[0].typeParameters)) {
|
||||
const minTypeArgumentCount = getMinTypeArgumentCount(signatures[0].typeParameters);
|
||||
const paramMessage = length(signatures[0].typeParameters) > minTypeArgumentCount ?
|
||||
`${minTypeArgumentCount}-${length(signatures[0].typeParameters)}` :
|
||||
minTypeArgumentCount.toString();
|
||||
reportError(Diagnostics.Expected_0_type_arguments_but_got_1, paramMessage, typeArguments.length.toString());
|
||||
}
|
||||
else {
|
||||
const argMessage = getSpreadArgumentIndex(args) > -1 ?
|
||||
"a minimum of " + (args.length - 1) :
|
||||
args.length.toString();
|
||||
const paramMessage = signatures[0].hasRestParameter ? "at least " + signatures[0].minArgumentCount :
|
||||
signatures[0].minArgumentCount < signatures[0].parameters.length ? `${signatures[0].minArgumentCount}-${signatures[0].parameters.length}` :
|
||||
signatures[0].minArgumentCount.toString();
|
||||
reportError(Diagnostics.Expected_0_arguments_but_got_1, paramMessage, argMessage);
|
||||
}
|
||||
}
|
||||
else {
|
||||
reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
|
||||
}
|
||||
}
|
||||
|
||||
// No signature was applicable. We have already reported the errors for the invalid signature.
|
||||
|
||||
@ -1855,6 +1855,14 @@
|
||||
"category": "Error",
|
||||
"code": 2552
|
||||
},
|
||||
"Expected {0} arguments, but got {1}.": {
|
||||
"category": "Error",
|
||||
"code": 2553
|
||||
},
|
||||
"Expected {0} type arguments, but got {1}.": {
|
||||
"category": "Error",
|
||||
"code": 2554
|
||||
},
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user