diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8ee0a4c051996..970f020f5f9f1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14860,6 +14860,14 @@ 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)); + } if (target.flags & TypeFlags.TypeVariable) { // If target is a type parameter, make an inference, unless the source type contains // the anyFunctionType (the wildcard type that's used to avoid contextually typing functions). @@ -14921,9 +14929,6 @@ namespace ts { } } } - else if (target.flags & TypeFlags.Substitution) { - inferFromTypes(source, (target as SubstitutionType).typeVariable); - } if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (source).target === (target).target) { // If source and target are references to the same generic type, infer from type arguments const sourceTypes = (source).typeArguments || emptyArray;