diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 970f020f5f9f1..bca3ca1bf1f8a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10318,8 +10318,16 @@ namespace ts { return links.resolvedType; } - function getActualTypeVariable(type: Type) { - return type.flags & TypeFlags.Substitution ? (type).typeVariable : type; + function getActualTypeVariable(type: Type): Type { + if (type.flags & TypeFlags.Substitution) { + return (type).typeVariable; + } + if (type.flags & TypeFlags.IndexedAccess && ( + (type).objectType.flags & TypeFlags.Substitution || + (type).indexType.flags & TypeFlags.Substitution)) { + return getIndexedAccessType(getActualTypeVariable((type).objectType), getActualTypeVariable((type).indexType)); + } + return type; } /** @@ -14860,13 +14868,8 @@ namespace ts { target = removeTypesFromUnionOrIntersection(target, matchingTypes); } } - else if (target.flags & TypeFlags.Substitution) { - target = (target as SubstitutionType).typeVariable; - } - else if (target.flags & TypeFlags.IndexedAccess && ( - (target).objectType.flags & TypeFlags.Substitution || - (target).indexType.flags & TypeFlags.Substitution)) { - target = getIndexedAccessType(getActualTypeVariable((target).objectType), getActualTypeVariable((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