Skip to content

Commit d7aa40d

Browse files
committed
Remove unnecessary subtype reduction operations
1 parent 60cc5df commit d7aa40d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ namespace ts {
15481548
}
15491549

15501550
function createBooleanType(trueFalseTypes: Type[]): IntrinsicType & UnionType {
1551-
const type = <IntrinsicType & UnionType>getUnionType(trueFalseTypes, /*subtypeReduction*/ true);
1551+
const type = <IntrinsicType & UnionType>getUnionType(trueFalseTypes);
15521552
type.flags |= TypeFlags.Boolean;
15531553
type.intrinsicName = "boolean";
15541554
return type;
@@ -5284,13 +5284,13 @@ namespace ts {
52845284
return type1.id - type2.id;
52855285
}
52865286

5287-
// We reduce the constituent type set to only include types that aren't subtypes of other types, unless
5288-
// the noSubtypeReduction flag is specified, in which case we perform a simple deduplication based on
5289-
// object identity. Subtype reduction is possible only when union types are known not to circularly
5290-
// reference themselves (as is the case with union types created by expression constructs such as array
5291-
// literals and the || and ?: operators). Named types can circularly reference themselves and therefore
5292-
// cannot be deduplicated during their declaration. For example, "type Item = string | (() => Item" is
5293-
// a named type that circularly references itself.
5287+
// We deduplicate the constituent types based on object identity. If the subtypeReduction flag is
5288+
// specified we also reduce the constituent type set to only include types that aren't subtypes of
5289+
// other types. Subtype reduction is expensive for large union types and is possible only when union
5290+
// types are known not to circularly reference themselves (as is the case with union types created by
5291+
// expression constructs such as array literals and the || and ?: operators). Named types can
5292+
// circularly reference themselves and therefore cannot be deduplicated during their declaration.
5293+
// For example, "type Item = string | (() => Item" is a named type that circularly references itself.
52945294
function getUnionType(types: Type[], subtypeReduction?: boolean, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type {
52955295
if (types.length === 0) {
52965296
return neverType;
@@ -7885,7 +7885,7 @@ namespace ts {
78857885
function getTypeWithDefault(type: Type, defaultExpression: Expression) {
78867886
if (defaultExpression) {
78877887
const defaultType = checkExpression(defaultExpression);
7888-
return getUnionType([getTypeWithFacts(type, TypeFacts.NEUndefined), defaultType], /*subtypeReduction*/ true);
7888+
return getUnionType([getTypeWithFacts(type, TypeFacts.NEUndefined), defaultType]);
78897889
}
78907890
return type;
78917891
}
@@ -9125,7 +9125,7 @@ namespace ts {
91259125
for (let i = indexOfParameter; i < iife.arguments.length; i++) {
91269126
restTypes.push(getTypeOfExpression(iife.arguments[i]));
91279127
}
9128-
return createArrayType(getUnionType(restTypes, /*subtypeReduction*/ true));
9128+
return createArrayType(getUnionType(restTypes));
91299129
}
91309130
const links = getNodeLinks(iife);
91319131
const cached = links.resolvedSignature;
@@ -9328,7 +9328,7 @@ namespace ts {
93289328
}
93299329
}
93309330
}
9331-
return mappedTypes ? getUnionType(mappedTypes, /*subtypeReduction*/ true) : mappedType;
9331+
return mappedTypes ? getUnionType(mappedTypes) : mappedType;
93329332
}
93339333

93349334
function getTypeOfPropertyOfContextualType(type: Type, name: string) {
@@ -14619,7 +14619,7 @@ namespace ts {
1461914619
case SyntaxKind.ClassDeclaration:
1462014620
const classSymbol = getSymbolOfNode(node.parent);
1462114621
const classConstructorType = getTypeOfSymbol(classSymbol);
14622-
expectedReturnType = getUnionType([classConstructorType, voidType], /*subtypeReduction*/ true);
14622+
expectedReturnType = getUnionType([classConstructorType, voidType]);
1462314623
break;
1462414624

1462514625
case SyntaxKind.Parameter:
@@ -14642,7 +14642,7 @@ namespace ts {
1464214642
case SyntaxKind.SetAccessor:
1464314643
const methodType = getTypeOfNode(node.parent);
1464414644
const descriptorType = createTypedPropertyDescriptorType(methodType);
14645-
expectedReturnType = getUnionType([descriptorType, voidType], /*subtypeReduction*/ true);
14645+
expectedReturnType = getUnionType([descriptorType, voidType]);
1464614646
break;
1464714647
}
1464814648

0 commit comments

Comments
 (0)