Defer reduction of identical function types in unions and intersections

This commit is contained in:
Anders Hejlsberg 2018-09-02 08:58:00 -07:00
parent 45101491c0
commit 059fcc9aa9

View File

@ -8691,10 +8691,7 @@ namespace ts {
const len = typeSet.length;
const index = len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues);
if (index < 0) {
if (!(flags & TypeFlags.Object && (<ObjectType>type).objectFlags & ObjectFlags.Anonymous &&
type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) {
typeSet.splice(~index, 0, type);
}
typeSet.splice(~index, 0, type);
}
}
}
@ -8710,15 +8707,6 @@ namespace ts {
return includes;
}
function containsIdenticalType(types: ReadonlyArray<Type>, type: Type) {
for (const t of types) {
if (isTypeIdenticalTo(t, type)) {
return true;
}
}
return false;
}
function isSubtypeOfAny(source: Type, targets: ReadonlyArray<Type>): boolean {
for (const target of targets) {
if (source !== target && isTypeSubtypeOf(source, target) && (
@ -8899,10 +8887,7 @@ namespace ts {
if (flags & TypeFlags.AnyOrUnknown) {
if (type === wildcardType) includes |= TypeFlags.Wildcard;
}
else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !contains(typeSet, type) &&
!(flags & TypeFlags.Object && (<ObjectType>type).objectFlags & ObjectFlags.Anonymous &&
type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) &&
containsIdenticalType(typeSet, type))) {
else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !contains(typeSet, type)) {
typeSet.push(type);
}
}