Fixes #35735: Avoids listing missing properties for types with only call/construct signatures (#40973)

* Fixes #35735

* fixes #35735

* PR feedback

Co-authored-by: Wesley Wigham <wewigham@microsoft.com>
This commit is contained in:
liewrichmond
2022-03-04 16:54:38 -05:00
committed by GitHub
parent 5f9f9e3752
commit ae62da9413
20 changed files with 196 additions and 73 deletions

View File

@@ -19996,7 +19996,7 @@ namespace ts {
const requireOptionalProperties = (relation === subtypeRelation || relation === strictSubtypeRelation) && !isObjectLiteralType(source) && !isEmptyArrayLiteralType(source) && !isTupleType(source);
const unmatchedProperty = getUnmatchedProperty(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false);
if (unmatchedProperty) {
if (reportErrors) {
if (reportErrors && shouldReportUnmatchedPropertyError(source, target)) {
reportUnmatchedProperty(source, target, unmatchedProperty, requireOptionalProperties);
}
return Ternary.False;
@@ -20154,6 +20154,20 @@ namespace ts {
return result;
}
function shouldReportUnmatchedPropertyError(source: Type, target: Type): boolean {
const typeCallSignatures = getSignaturesOfStructuredType(source, SignatureKind.Call);
const typeConstructSignatures = getSignaturesOfStructuredType(source, SignatureKind.Construct);
const typeProperties = getPropertiesOfObjectType(source);
if ((typeCallSignatures.length || typeConstructSignatures.length) && !typeProperties.length) {
if ((getSignaturesOfType(target, SignatureKind.Call).length && typeCallSignatures.length) ||
(getSignaturesOfType(target, SignatureKind.Construct).length && typeConstructSignatures.length)) {
return true; // target has similar signature kinds to source, still focus on the unmatched property
}
return false;
}
return true;
}
function reportIncompatibleCallSignatureReturn(siga: Signature, sigb: Signature) {
if (siga.parameters.length === 0 && sigb.parameters.length === 0) {
return (source: Type, target: Type) => reportIncompatibleError(Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types_0_and_1, typeToString(source), typeToString(target));