Add error message

Add error message when trying to relate primitives to the boxed/apparent
backing types.
This commit is contained in:
Yuichi Nukiyama
2016-08-20 12:36:57 +09:00
parent d8ab098195
commit 806e142cbf
15 changed files with 95 additions and 1 deletions

View File

@@ -6258,13 +6258,20 @@ namespace ts {
targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
}
// check if trying to relate primitives to the boxed/apparent backing types.
if ((sourceType === "Number" && targetType === "number") ||
(sourceType === "String" && targetType === "string") ||
(sourceType === "Boolean" && targetType === "boolean")) {
reportError(Diagnostics._0_is_a_primitive_type_while_1_is_a_boxed_object_Prefer_using_0_when_possible, targetType, sourceType);
}
if (!message) {
message = relation === comparableRelation ?
Diagnostics.Type_0_is_not_comparable_to_type_1 :
Diagnostics.Type_0_is_not_assignable_to_type_1;
}
reportError(message, sourceType, targetType);
reportError(message, sourceType, targetType);
}
// Compare two types and return

View File

@@ -1955,6 +1955,10 @@
"category": "Error",
"code": 2691
},
"'{0}' is a primitive type while '{1}' is a boxed object. Prefer using '{0}' when possible.": {
"category": "Error",
"code": 2692
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000