mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user