@@ -3742,6 +3742,10 @@ namespace ts {
37423742 return result;
37433743 }
37443744
3745+ function createOriginType(flags: TypeFlags): Type {
3746+ return new Type(checker, flags);
3747+ }
3748+
37453749 function createIntrinsicType(kind: TypeFlags, intrinsicName: string, objectFlags: ObjectFlags = 0): IntrinsicType {
37463750 const type = <IntrinsicType>createType(kind);
37473751 type.intrinsicName = intrinsicName;
@@ -13263,6 +13267,12 @@ namespace ts {
1326313267 }
1326413268 }
1326513269
13270+ function createOriginUnionOrIntersectionType(flags: TypeFlags, types: Type[]) {
13271+ const result = <UnionOrIntersectionType>createOriginType(flags);
13272+ result.types = types;
13273+ return result;
13274+ }
13275+
1326613276 // We sort and deduplicate the constituent types based on object identity. If the subtypeReduction
1326713277 // flag is specified we also reduce the constituent type set to only include types that aren't subtypes
1326813278 // of other types. Subtype reduction is expensive for large union types and is possible only when union
@@ -13323,7 +13333,7 @@ namespace ts {
1332313333 for (const t of namedUnions) {
1332413334 insertType(reducedTypes, t);
1332513335 }
13326- origin = createUnionType( reducedTypes);
13336+ origin = createOriginUnionOrIntersectionType(TypeFlags.Union, reducedTypes);
1332713337 }
1332813338 }
1332913339 const objectFlags = (includes & TypeFlags.NotPrimitiveUnion ? 0 : ObjectFlags.PrimitiveUnion) |
@@ -13648,7 +13658,7 @@ namespace ts {
1364813658 const constituents = getCrossProductIntersections(typeSet);
1364913659 // We attach a denormalized origin type when at least one constituent of the cross-product union is an
1365013660 // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions).
13651- const origin = some(constituents, t => !!(t.flags & TypeFlags.Intersection)) ? createIntersectionType( typeSet) : undefined;
13661+ const origin = some(constituents, t => !!(t.flags & TypeFlags.Intersection)) ? createOriginUnionOrIntersectionType(TypeFlags.Intersection, typeSet) : undefined;
1365213662 result = getUnionType(constituents, UnionReduction.Literal, aliasSymbol, aliasTypeArguments, origin);
1365313663 }
1365413664 }
@@ -13711,6 +13721,12 @@ namespace ts {
1371113721 return result;
1371213722 }
1371313723
13724+ function createOriginIndexType(type: InstantiableType | UnionOrIntersectionType) {
13725+ const result = <IndexType>createOriginType(TypeFlags.Index);
13726+ result.type = type;
13727+ return result;
13728+ }
13729+
1371413730 function getIndexTypeForGenericType(type: InstantiableType | UnionOrIntersectionType, stringsOnly: boolean) {
1371513731 return stringsOnly ?
1371613732 type.resolvedStringIndexType || (type.resolvedStringIndexType = createIndexType(type, /*stringsOnly*/ true)) :
@@ -13773,7 +13789,7 @@ namespace ts {
1377313789 }
1377413790
1377513791 function getLiteralTypeFromProperties(type: Type, include: TypeFlags, includeOrigin: boolean) {
13776- const origin = includeOrigin && (getObjectFlags(type) & (ObjectFlags.ClassOrInterface | ObjectFlags.Reference) || type.aliasSymbol) ? createIndexType (type, /*stringsOnly*/ false ) : undefined;
13792+ const origin = includeOrigin && (getObjectFlags(type) & (ObjectFlags.ClassOrInterface | ObjectFlags.Reference) || type.aliasSymbol) ? createOriginIndexType (type) : undefined;
1377713793 return getUnionType(map(getPropertiesOfType(type), p => getLiteralTypeFromProperty(p, include)), UnionReduction.Literal,
1377813794 /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined, origin);
1377913795 }
0 commit comments