Skip to content

Commit 46d1c4e

Browse files
committed
Add comments
1 parent 5e29a0a commit 46d1c4e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16260,6 +16260,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1626016260
let lastUnion: Type | undefined;
1626116261
for (const type of types) {
1626216262
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).
1626316266
if (type !== lastUnion) {
1626416267
includes = addTypesToUnion(typeSet, includes | (isNamedUnionType(type) ? TypeFlags.Union : 0), (type as UnionType).types);
1626516268
lastUnion = type;
@@ -16419,6 +16422,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1641916422
if (types.length === 1) {
1642016423
return types[0];
1642116424
}
16425+
// We optimize for the common case of unioning a union type with some other type (such as `undefined`).
1642216426
if (types.length === 2 && !origin && (types[0].flags & TypeFlags.Union || types[1].flags & TypeFlags.Union)) {
1642316427
const infix = unionReduction === UnionReduction.None ? "N" : unionReduction === UnionReduction.Subtype ? "S" : "L";
1642416428
const id = types[0].id + infix + types[1].id + getAliasId(aliasSymbol, aliasTypeArguments);

0 commit comments

Comments
 (0)