@@ -6258,13 +6258,6 @@ namespace ts {
62586258 targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
62596259 }
62606260
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-
62686261 if (!message) {
62696262 message = relation === comparableRelation ?
62706263 Diagnostics.Type_0_is_not_comparable_to_type_1 :
@@ -6274,6 +6267,19 @@ namespace ts {
62746267 reportError(message, sourceType, targetType);
62756268 }
62766269
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+
62776283 // Compare two types and return
62786284 // Ternary.True if they are related with no assumptions,
62796285 // Ternary.Maybe if they are related with assumptions of other relationships, or
@@ -6396,6 +6402,10 @@ namespace ts {
63966402 }
63976403 }
63986404
6405+ if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) {
6406+ tryElaborateErrorsForPrimitivesAndObjects(source, target);
6407+ }
6408+
63996409 if (reportErrors) {
64006410 reportRelationError(headMessage, source, target);
64016411 }
0 commit comments