Skip to content

Commit

Permalink
Move substitution type elimination to getActualTypeVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Apr 30, 2019
1 parent ed75e1d commit 1818218
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/compiler/checker.ts
Expand Up @@ -10318,8 +10318,16 @@ namespace ts {
return links.resolvedType;
}

function getActualTypeVariable(type: Type) {
return type.flags & TypeFlags.Substitution ? (<SubstitutionType>type).typeVariable : type;
function getActualTypeVariable(type: Type): 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;
}

/**
Expand Down Expand Up @@ -14860,13 +14868,8 @@ namespace ts {
target = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, matchingTypes);
}
}
else if (target.flags & TypeFlags.Substitution) {
target = (target as SubstitutionType).typeVariable;
}
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));
else if (target.flags & (TypeFlags.IndexedAccess | TypeFlags.Substitution)) {
target = getActualTypeVariable(target);
}
if (target.flags & TypeFlags.TypeVariable) {
// If target is a type parameter, make an inference, unless the source type contains
Expand Down

0 comments on commit 1818218

Please sign in to comment.