Skip to content

Commit

Permalink
Only check if the index type should be deferred for intersection types
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Aug 31, 2022
1 parent 00e3926 commit 2ba9ff1
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2ba9ff1

Please sign in to comment.