mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Give a better message up-front for incompatible equality errors.
This commit is contained in:
@@ -20884,7 +20884,31 @@ namespace ts {
|
||||
}
|
||||
|
||||
function reportOperatorError() {
|
||||
error(errorNode || operatorToken, Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType));
|
||||
let err = chainDiagnosticMessages(
|
||||
/*elaboration*/ undefined,
|
||||
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2,
|
||||
tokenToString(operatorToken.kind),
|
||||
typeToString(leftType),
|
||||
typeToString(rightType)
|
||||
);
|
||||
err = giveBetterPrimaryError(err);
|
||||
|
||||
diagnostics.add(createDiagnosticForNodeFromMessageChain(
|
||||
errorNode || operatorToken,
|
||||
err
|
||||
));
|
||||
}
|
||||
|
||||
function giveBetterPrimaryError(elaboration: DiagnosticMessageChain) {
|
||||
switch (operatorToken.kind) {
|
||||
case SyntaxKind.EqualsEqualsEqualsToken:
|
||||
case SyntaxKind.EqualsEqualsToken:
|
||||
return chainDiagnosticMessages(elaboration, Diagnostics.The_types_of_these_values_indicates_that_this_condition_will_always_be_0, "false");
|
||||
case SyntaxKind.ExclamationEqualsEqualsToken:
|
||||
case SyntaxKind.ExclamationEqualsToken:
|
||||
return chainDiagnosticMessages(elaboration, Diagnostics.The_types_of_these_values_indicates_that_this_condition_will_always_be_0, "true");
|
||||
}
|
||||
return elaboration;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1252,6 +1252,10 @@
|
||||
"category": "Error",
|
||||
"code": 2366
|
||||
},
|
||||
"The types of these values indicates that this condition will always be '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2367
|
||||
},
|
||||
"Type parameter name cannot be '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2368
|
||||
|
||||
Reference in New Issue
Block a user