Skip to content

Commit 762fff1

Browse files
committed
Remove duplicate call/construct signatures in intersections
1 parent 3ca2e7d commit 762fff1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7234,8 +7234,8 @@ namespace ts {
72347234
function resolveIntersectionTypeMembers(type: IntersectionType) {
72357235
// The members and properties collections are empty for intersection types. To get all properties of an
72367236
// intersection type use getPropertiesOfType (only the language service uses this).
7237-
let callSignatures: ReadonlyArray<Signature> = emptyArray;
7238-
let constructSignatures: ReadonlyArray<Signature> = emptyArray;
7237+
let callSignatures: Signature[] | undefined;
7238+
let constructSignatures: Signature[] | undefined;
72397239
let stringIndexInfo: IndexInfo | undefined;
72407240
let numberIndexInfo: IndexInfo | undefined;
72417241
const types = type.types;
@@ -7257,13 +7257,22 @@ namespace ts {
72577257
return clone;
72587258
});
72597259
}
7260-
constructSignatures = concatenate(constructSignatures, signatures);
7260+
constructSignatures = appendSignatures(constructSignatures, signatures);
72617261
}
7262-
callSignatures = concatenate(callSignatures, getSignaturesOfType(t, SignatureKind.Call));
7262+
callSignatures = appendSignatures(callSignatures, getSignaturesOfType(t, SignatureKind.Call));
72637263
stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String));
72647264
numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number));
72657265
}
7266-
setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
7266+
setStructuredTypeMembers(type, emptySymbols, callSignatures || emptyArray, constructSignatures || emptyArray, stringIndexInfo, numberIndexInfo);
7267+
}
7268+
7269+
function appendSignatures(signatures: Signature[] | undefined, newSignatures: readonly Signature[]) {
7270+
for (const sig of newSignatures) {
7271+
if (!signatures || every(signatures, s => !compareSignaturesIdentical(s, sig, /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, compareTypesIdentical))) {
7272+
signatures = append(signatures, sig);
7273+
}
7274+
}
7275+
return signatures;
72677276
}
72687277

72697278
/**

0 commit comments

Comments
 (0)