Move substitution type elimination to getActualTypeVariable

This commit is contained in:
Anders Hejlsberg 2019-04-30 09:23:52 -07:00
parent ed75e1d07e
commit 1818218d59

View file

@ -10318,8 +10318,16 @@ namespace ts {
return links.resolvedType; return links.resolvedType;
} }
function getActualTypeVariable(type: Type) { function getActualTypeVariable(type: Type): Type {
return type.flags & TypeFlags.Substitution ? (<SubstitutionType>type).typeVariable : type; if (type.flags & TypeFlags.Substitution) {
return (<SubstitutionType>type).typeVariable;
}
if (type.flags & TypeFlags.IndexedAccess && (
(<IndexedAccessType>type).objectType.flags & TypeFlags.Substitution ||
(<IndexedAccessType>type).indexType.flags & TypeFlags.Substitution)) {
return getIndexedAccessType(getActualTypeVariable((<IndexedAccessType>type).objectType), getActualTypeVariable((<IndexedAccessType>type).indexType));
}
return type;
} }
/** /**
@ -14860,13 +14868,8 @@ namespace ts {
target = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, matchingTypes); target = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, matchingTypes);
} }
} }
else if (target.flags & TypeFlags.Substitution) { else if (target.flags & (TypeFlags.IndexedAccess | TypeFlags.Substitution)) {
target = (target as SubstitutionType).typeVariable; target = getActualTypeVariable(target);
}
else if (target.flags & TypeFlags.IndexedAccess && (
(<IndexedAccessType>target).objectType.flags & TypeFlags.Substitution ||
(<IndexedAccessType>target).indexType.flags & TypeFlags.Substitution)) {
target = getIndexedAccessType(getActualTypeVariable((<IndexedAccessType>target).objectType), getActualTypeVariable((<IndexedAccessType>target).indexType));
} }
if (target.flags & TypeFlags.TypeVariable) { if (target.flags & TypeFlags.TypeVariable) {
// If target is a type parameter, make an inference, unless the source type contains // If target is a type parameter, make an inference, unless the source type contains