Give a better message up-front for incompatible equality errors.

This commit is contained in:
Daniel Rosenwasser
2018-06-26 15:11:41 -07:00
parent cb6325d8ec
commit 63a52cd21e
2 changed files with 29 additions and 1 deletions

View File

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

View File

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