@@ -13798,15 +13798,17 @@ namespace ts {
13798
13798
}
13799
13799
return type;
13800
13800
}
13801
- if (flags & TypeFlags.Union && !(flags & TypeFlags.Primitive)) {
13802
- const types = (<UnionType>type).types;
13803
- const newTypes = instantiateTypes(types, mapper);
13804
- return newTypes !== types ? getUnionType(newTypes, UnionReduction.Literal, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) : type;
13805
- }
13806
- if (flags & TypeFlags.Intersection) {
13807
- const types = (<IntersectionType>type).types;
13801
+ if ((flags & TypeFlags.Intersection) || (flags & TypeFlags.Union && !(flags & TypeFlags.Primitive))) {
13802
+ if (!couldContainTypeVariables(type)) {
13803
+ return type;
13804
+ }
13805
+ const types = (<UnionOrIntersectionType>type).types;
13808
13806
const newTypes = instantiateTypes(types, mapper);
13809
- return newTypes !== types ? getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) : type;
13807
+ return newTypes === types
13808
+ ? type
13809
+ : (flags & TypeFlags.Intersection)
13810
+ ? getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper))
13811
+ : getUnionType(newTypes, UnionReduction.Literal, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
13810
13812
}
13811
13813
if (flags & TypeFlags.Index) {
13812
13814
return getIndexType(instantiateType((<IndexType>type).type, mapper));
0 commit comments