mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Fix error message when type argument arity is wrong (#28366)
* Fix error message when type argument arity is wrong * Parenthesize 's' in plurals * Update baseline * Update baseline * Use old error message * Revert parantheses
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
3c408d8054
commit
e6aa992095
@@ -19890,14 +19890,31 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getTypeArgumentArityError(node: Node, signatures: ReadonlyArray<Signature>, typeArguments: NodeArray<TypeNode>) {
|
||||
let min = Infinity;
|
||||
let max = -Infinity;
|
||||
for (const sig of signatures) {
|
||||
min = Math.min(min, getMinTypeArgumentCount(sig.typeParameters));
|
||||
max = Math.max(max, length(sig.typeParameters));
|
||||
const argCount = typeArguments.length;
|
||||
// No overloads exist
|
||||
if (signatures.length === 1) {
|
||||
const sig = signatures[0];
|
||||
const min = getMinTypeArgumentCount(sig.typeParameters);
|
||||
const max = length(sig.typeParameters);
|
||||
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, min < max ? min + "-" + max : min , argCount);
|
||||
}
|
||||
const paramCount = min === max ? min : min + "-" + max;
|
||||
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length);
|
||||
// Overloads exist
|
||||
let belowArgCount = -Infinity;
|
||||
let aboveArgCount = Infinity;
|
||||
for (const sig of signatures) {
|
||||
const min = getMinTypeArgumentCount(sig.typeParameters);
|
||||
const max = length(sig.typeParameters);
|
||||
if (min > argCount) {
|
||||
aboveArgCount = Math.min(aboveArgCount, min);
|
||||
}
|
||||
else if (max < argCount) {
|
||||
belowArgCount = Math.max(belowArgCount, max);
|
||||
}
|
||||
}
|
||||
if (belowArgCount !== -Infinity && aboveArgCount !== Infinity) {
|
||||
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.No_overload_expects_0_type_arguments_but_overloads_do_exist_that_expect_either_1_or_2_type_arguments, argCount, belowArgCount, aboveArgCount);
|
||||
}
|
||||
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount);
|
||||
}
|
||||
|
||||
function resolveCall(node: CallLikeExpression, signatures: ReadonlyArray<Signature>, candidatesOutArray: Signature[] | undefined, isForSignatureHelp: boolean, fallbackError?: DiagnosticMessage): Signature {
|
||||
|
||||
@@ -2533,6 +2533,10 @@
|
||||
"category": "Error",
|
||||
"code": 2742
|
||||
},
|
||||
"No overload expects {0} type arguments, but overloads do exist that expect either {1} or {2} type arguments.": {
|
||||
"category": "Error",
|
||||
"code": 2743
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
Reference in New Issue
Block a user