follow advise
This commit is contained in:
parent
37a9e6a9cc
commit
0c01874b31
3 changed files with 25 additions and 9 deletions
|
@ -6258,13 +6258,6 @@ 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 :
|
||||
|
@ -6274,6 +6267,19 @@ namespace ts {
|
|||
reportError(message, sourceType, targetType);
|
||||
}
|
||||
|
||||
function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
|
||||
const sourceType = typeToString(source);
|
||||
const targetType = typeToString(target);
|
||||
|
||||
if ((globalStringType === source && stringType === target) ||
|
||||
(globalNumberType === source && numberType === target) ||
|
||||
(globalBooleanType === source && booleanType === target) ||
|
||||
(getGlobalESSymbolType() === source && esSymbolType === target)) {
|
||||
console.log(source);console.log(target);
|
||||
reportError(Diagnostics._0_is_a_primitive_type_while_1_is_a_boxed_object_Prefer_using_0_when_possible, targetType, sourceType);
|
||||
}
|
||||
}
|
||||
|
||||
// Compare two types and return
|
||||
// Ternary.True if they are related with no assumptions,
|
||||
// Ternary.Maybe if they are related with assumptions of other relationships, or
|
||||
|
@ -6396,6 +6402,10 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) {
|
||||
tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
||||
}
|
||||
|
||||
if (reportErrors) {
|
||||
reportRelationError(headMessage, source, target);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
tests/cases/conformance/es6/Symbols/symbolType15.ts(5,1): error TS2322: Type 'Symbol' is not assignable to type 'symbol'.
|
||||
'symbol' is a primitive type while 'Symbol' is a boxed object. Prefer using 'symbol' when possible.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/Symbols/symbolType15.ts (1 errors) ====
|
||||
|
@ -8,4 +9,5 @@ tests/cases/conformance/es6/Symbols/symbolType15.ts(5,1): error TS2322: Type 'Sy
|
|||
symObj = sym;
|
||||
sym = symObj;
|
||||
~~~
|
||||
!!! error TS2322: Type 'Symbol' is not assignable to type 'symbol'.
|
||||
!!! error TS2322: Type 'Symbol' is not assignable to type 'symbol'.
|
||||
!!! error TS2322: 'symbol' is a primitive type while 'Symbol' is a boxed object. Prefer using 'symbol' when possible.
|
|
@ -8,4 +8,8 @@ s = S;
|
|||
|
||||
var B = new Boolean();
|
||||
var b = true;
|
||||
b = B;
|
||||
b = B;
|
||||
|
||||
var sym: symbol;
|
||||
var Sym: Symbol;
|
||||
sym = Sym;
|
Loading…
Reference in a new issue