File tree 1 file changed +4
-0
lines changed
1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -16260,6 +16260,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
16260
16260
let lastUnion: Type | undefined;
16261
16261
for (const type of types) {
16262
16262
if (type.flags & TypeFlags.Union) {
16263
+ // We skip the union type if it is the same as the last union we processed. We could potentially track
16264
+ // all union types that we've processed, but this simple test is fast and covers the scenarios we care
16265
+ // about (in particular, Record<A, B>[A], where A and B are large union types).
16263
16266
if (type !== lastUnion) {
16264
16267
includes = addTypesToUnion(typeSet, includes | (isNamedUnionType(type) ? TypeFlags.Union : 0), (type as UnionType).types);
16265
16268
lastUnion = type;
@@ -16419,6 +16422,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
16419
16422
if (types.length === 1) {
16420
16423
return types[0];
16421
16424
}
16425
+ // We optimize for the common case of unioning a union type with some other type (such as `undefined`).
16422
16426
if (types.length === 2 && !origin && (types[0].flags & TypeFlags.Union || types[1].flags & TypeFlags.Union)) {
16423
16427
const infix = unionReduction === UnionReduction.None ? "N" : unionReduction === UnionReduction.Subtype ? "S" : "L";
16424
16428
const id = types[0].id + infix + types[1].id + getAliasId(aliasSymbol, aliasTypeArguments);
You can’t perform that action at this time.
0 commit comments