From 12b80f3183cd97aacf448c29d609aa4b56be260c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 11 Jan 2018 16:26:38 -0800 Subject: [PATCH] Keep string index from intersections in base constraint of index type --- src/compiler/checker.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d402f344d60..a32104c0535 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6468,7 +6468,7 @@ namespace ts { } function getConstraintOfIndexedAccess(type: IndexedAccessType) { - const transformed = getSimplifiedIndexedAccessType(type); + const transformed = getSubstitutedIndexedMappedType(type); if (transformed) { return transformed; } @@ -8383,6 +8383,11 @@ namespace ts { getIntersectionType(stringIndexTypes) ]); } + return getSubstitutedIndexedMappedType(type); + } + + function getSubstitutedIndexedMappedType(type: IndexedAccessType): Type { + const objectType = type.objectType; // If the object type is a mapped type { [P in K]: E }, where K is generic, instantiate E using a mapper // that substitutes the index type for P. For example, for an index access { [P in K]: Box }[X], we // construct the type Box.