From 0759bc67a471ddd8c47dd652d836e96eb1be4819 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 27 Apr 2019 16:19:50 -0700 Subject: [PATCH] Fix inference to indexed access type containing substitution type --- src/compiler/checker.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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;