Add specific weak type error for callable types

"Did you mean to call it?"
This commit is contained in:
Nathan Shively-Sanders
2017-08-08 11:25:32 -07:00
parent 781da2332d
commit 7ff1d8e797
5 changed files with 27 additions and 15 deletions

View File

@@ -8944,7 +8944,15 @@ namespace ts {
isWeakType(target) &&
!hasCommonProperties(source, target)) {
if (reportErrors) {
reportError(Diagnostics.Type_0_has_no_properties_in_common_with_type_1, typeToString(source), typeToString(target));
const calls = getSignaturesOfType(source, SignatureKind.Call);
const constructs = getSignaturesOfType(source, SignatureKind.Construct);
if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, /*reportErrors*/ false) ||
constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, /*reportErrors*/ false)) {
reportError(Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, typeToString(source), typeToString(target));
}
else {
reportError(Diagnostics.Type_0_has_no_properties_in_common_with_type_1, typeToString(source), typeToString(target));
}
}
return Ternary.False;
}

View File

@@ -1908,6 +1908,10 @@
"category": "Error",
"code": 2559
},
"Value of type '{0}' has no properties in common with type '{1}'. Did you mean to call it?": {
"category": "Error",
"code": 2560
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600