@@ -6258,13 +6258,6 @@ namespace ts {
6258
6258
targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
6259
6259
}
6260
6260
6261
- // check if trying to relate primitives to the boxed/apparent backing types.
6262
- if ((sourceType === "Number" && targetType === "number") ||
6263
- (sourceType === "String" && targetType === "string") ||
6264
- (sourceType === "Boolean" && targetType === "boolean")) {
6265
- reportError(Diagnostics._0_is_a_primitive_type_while_1_is_a_boxed_object_Prefer_using_0_when_possible, targetType, sourceType);
6266
- }
6267
-
6268
6261
if (!message) {
6269
6262
message = relation === comparableRelation ?
6270
6263
Diagnostics.Type_0_is_not_comparable_to_type_1 :
@@ -6274,6 +6267,19 @@ namespace ts {
6274
6267
reportError(message, sourceType, targetType);
6275
6268
}
6276
6269
6270
+ function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
6271
+ const sourceType = typeToString(source);
6272
+ const targetType = typeToString(target);
6273
+
6274
+ if ((globalStringType === source && stringType === target) ||
6275
+ (globalNumberType === source && numberType === target) ||
6276
+ (globalBooleanType === source && booleanType === target) ||
6277
+ (getGlobalESSymbolType() === source && esSymbolType === target)) {
6278
+ console.log(source);console.log(target);
6279
+ reportError(Diagnostics._0_is_a_primitive_type_while_1_is_a_boxed_object_Prefer_using_0_when_possible, targetType, sourceType);
6280
+ }
6281
+ }
6282
+
6277
6283
// Compare two types and return
6278
6284
// Ternary.True if they are related with no assumptions,
6279
6285
// Ternary.Maybe if they are related with assumptions of other relationships, or
@@ -6396,6 +6402,10 @@ namespace ts {
6396
6402
}
6397
6403
}
6398
6404
6405
+ if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) {
6406
+ tryElaborateErrorsForPrimitivesAndObjects(source, target);
6407
+ }
6408
+
6399
6409
if (reportErrors) {
6400
6410
reportRelationError(headMessage, source, target);
6401
6411
}
0 commit comments