Skip to content

Commit 6c1248e

Browse files
committed
Preserve aliases for intersection and indexed access types
1 parent b2434fc commit 6c1248e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10022,7 +10022,8 @@ namespace ts {
1002210022
}
1002310023
}
1002410024
else if (type.flags & TypeFlags.Intersection) {
10025-
return getIntersectionType(map((<IntersectionType>type).types, t => getTypeWithThisArgument(t, thisArgument, needApparentType)));
10025+
const types = sameMap((<IntersectionType>type).types, t => getTypeWithThisArgument(t, thisArgument, needApparentType));
10026+
return types !== (<IntersectionType>type).types ? getIntersectionType(types) : type;
1002610027
}
1002710028
return needApparentType ? getApparentType(type) : type;
1002810029
}
@@ -13348,7 +13349,7 @@ namespace ts {
1334813349
if (types.length === 1) {
1334913350
return types[0];
1335013351
}
13351-
const id = getTypeListId(types) + (origin ? `${origin.isIntersection ? '&' : '|'}${getTypeListId(origin.types)}` : "") + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
13352+
const id = (origin ? `${origin.isIntersection ? "&" : "|"}${getTypeListId(origin.types)}` : getTypeListId(types)) + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
1335213353
let type = unionTypes.get(id);
1335313354
if (!type) {
1335413355
type = <UnionType>createType(TypeFlags.Union);
@@ -13595,7 +13596,7 @@ namespace ts {
1359513596
if (typeSet.length === 1) {
1359613597
return typeSet[0];
1359713598
}
13598-
const id = getTypeListId(typeSet);
13599+
const id = getTypeListId(typeSet) + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
1359913600
let result = intersectionTypes.get(id);
1360013601
if (!result) {
1360113602
if (includes & TypeFlags.Union) {
@@ -13606,10 +13607,10 @@ namespace ts {
1360613607
result = getIntersectionType(typeSet, aliasSymbol, aliasTypeArguments);
1360713608
}
1360813609
else if (extractIrreducible(typeSet, TypeFlags.Undefined)) {
13609-
result = getUnionTypeFromIntersection([getIntersectionType(typeSet), undefinedType], aliasSymbol, aliasTypeArguments, typeSet);
13610+
result = getUnionTypeFromIntersection([getIntersectionType(typeSet), undefinedType], aliasSymbol, aliasTypeArguments);
1361013611
}
1361113612
else if (extractIrreducible(typeSet, TypeFlags.Null)) {
13612-
result = getUnionTypeFromIntersection([getIntersectionType(typeSet), nullType], aliasSymbol, aliasTypeArguments, typeSet);
13613+
result = getUnionTypeFromIntersection([getIntersectionType(typeSet), nullType], aliasSymbol, aliasTypeArguments);
1361313614
}
1361413615
else {
1361513616
// We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of
@@ -13632,8 +13633,8 @@ namespace ts {
1363213633
return result;
1363313634
}
1363413635

13635-
function getUnionTypeFromIntersection(types: readonly Type[], aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined, originalTypes: readonly Type[]) {
13636-
const origin = some(types, t => !!(t.flags & TypeFlags.Intersection)) ? { types: originalTypes, isIntersection: true } : undefined;
13636+
function getUnionTypeFromIntersection(types: readonly Type[], aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined, originalTypes?: readonly Type[]) {
13637+
const origin = originalTypes && some(types, t => !!(t.flags & TypeFlags.Intersection)) ? { types: originalTypes, isIntersection: true } : undefined;
1363713638
return getUnionType(types, UnionReduction.Literal, aliasSymbol, aliasTypeArguments, origin);
1363813639
}
1363913640

@@ -14328,7 +14329,7 @@ namespace ts {
1432814329
return objectType;
1432914330
}
1433014331
// Defer the operation by creating an indexed access type.
14331-
const id = objectType.id + "," + indexType.id + (shouldIncludeUndefined ? "?" : "");
14332+
const id = objectType.id + "," + indexType.id + (shouldIncludeUndefined ? "?" : "") + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
1433214333
let type = indexedAccessTypes.get(id);
1433314334
if (!type) {
1433414335
indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType, aliasSymbol, aliasTypeArguments, shouldIncludeUndefined));

0 commit comments

Comments
 (0)