File tree 1 file changed +8
-1
lines changed 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -18176,7 +18176,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
18176
18176
const declarations = concatenate(leftProp.declarations, rightProp.declarations);
18177
18177
const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional);
18178
18178
const result = createSymbol(flags, leftProp.escapedName);
18179
- result.links.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)], UnionReduction.Subtype);
18179
+ // Optimization: avoid calculating the union type if spreading into the exact same type.
18180
+ // This is common, e.g. spreading one options bag into another where the bags have the
18181
+ // same type, or have properties which overlap. If the unions are large, it may turn out
18182
+ // to be expensive to perform subtype reduction.
18183
+ const leftType = getTypeOfSymbol(leftProp);
18184
+ const leftTypeWithoutUndefined = removeMissingOrUndefinedType(leftType);
18185
+ const rightTypeWithoutUndefined = removeMissingOrUndefinedType(rightType);
18186
+ result.links.type = leftTypeWithoutUndefined === rightTypeWithoutUndefined ? leftType : getUnionType([leftType, rightTypeWithoutUndefined], UnionReduction.Subtype);
18180
18187
result.links.leftSpread = leftProp;
18181
18188
result.links.rightSpread = rightProp;
18182
18189
result.declarations = declarations;
You can’t perform that action at this time.
0 commit comments