From 2ba9ff19c841c8f9fc6ebc361464a10a9008f529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 31 Aug 2022 07:50:47 +0200 Subject: [PATCH] Only check if the index type should be deferred for intersection types --- src/compiler/checker.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 70daadb0923..f10e4f92e04 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15903,13 +15903,10 @@ namespace ts { } function distributeIndexOverObjectType(objectType: Type, indexType: Type, writing: boolean) { - if (shouldDeferIndexType(objectType)) { - return; - } // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & TypeFlags.UnionOrIntersection) { + if (objectType.flags & TypeFlags.Union || objectType.flags & TypeFlags.Intersection && !shouldDeferIndexType(objectType)) { const types = map((objectType as UnionOrIntersectionType).types, t => getSimplifiedType(getIndexedAccessType(t, indexType), writing)); return objectType.flags & TypeFlags.Intersection || writing ? getIntersectionType(types) : getUnionType(types); }