mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
Improve the error message when asserting to a type that is not
comparable to the original. Also improve the error message for implicit conversion of a symbol to a string in a template literal, which previously shared the error message with type assertions. Fixes #25539. Addresses #25870.
This commit is contained in:
@@ -20041,7 +20041,8 @@ namespace ts {
|
||||
if (produceDiagnostics && targetType !== errorType) {
|
||||
const widenedType = getWidenedType(exprType);
|
||||
if (!isTypeComparableTo(targetType, widenedType)) {
|
||||
checkTypeComparableTo(exprType, targetType, errNode, Diagnostics.Type_0_cannot_be_converted_to_type_1);
|
||||
checkTypeComparableTo(exprType, targetType, errNode,
|
||||
Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first);
|
||||
}
|
||||
}
|
||||
return targetType;
|
||||
@@ -21515,7 +21516,7 @@ namespace ts {
|
||||
// in tagged templates.
|
||||
forEach(node.templateSpans, templateSpan => {
|
||||
if (maybeTypeOfKind(checkExpression(templateSpan.expression), TypeFlags.ESSymbolLike)) {
|
||||
error(templateSpan.expression, Diagnostics.Type_0_cannot_be_converted_to_type_1, typeToString(esSymbolType), typeToString(stringType));
|
||||
error(templateSpan.expression, Diagnostics.Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1196,7 +1196,7 @@
|
||||
"category": "Error",
|
||||
"code": 2351
|
||||
},
|
||||
"Type '{0}' cannot be converted to type '{1}'.": {
|
||||
"Conversion of type '{0}' to type '{1}' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.": {
|
||||
"category": "Error",
|
||||
"code": 2352
|
||||
},
|
||||
@@ -2421,6 +2421,10 @@
|
||||
"category": "Error",
|
||||
"code": 2730
|
||||
},
|
||||
"Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'.": {
|
||||
"category": "Error",
|
||||
"code": 2731
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
Reference in New Issue
Block a user