Skip to content

Commit f1622f0

Browse files
committed
Use filter instead of unnecessary laziness
1 parent d74820d commit f1622f0

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

src/compiler/checker.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8389,18 +8389,11 @@ namespace ts {
83898389
}
83908390
// Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or
83918391
// more mapped types with a template type `never`, '(U & V & { [P in T]: never })[K]', return a
8392-
// transformed type that removes the never-mapped type: '(U & V)[K]'. This mirrors what would happen
8392+
// transformed type that removes the never-mapped type: '(U & V)[K]'. This mirrors what would happen
83938393
// eventually anyway, but it easier to reason about.
83948394
if (objectType.flags & TypeFlags.Intersection && isGenericObjectType(objectType) && some((<IntersectionType>objectType).types, isMappedTypeToNever)) {
8395-
let nonNeverTypes: Type[];
8396-
for (const t of (<IntersectionType>objectType).types) {
8397-
if (!isMappedTypeToNever(t)) {
8398-
(nonNeverTypes || (nonNeverTypes = [])).push(t);
8399-
}
8400-
}
8401-
if (nonNeverTypes) {
8402-
return getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType);
8403-
}
8395+
const nonNeverTypes = filter((<IntersectionType>objectType).types, t => !isMappedTypeToNever(t));
8396+
return getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType);
84048397
}
84058398

84068399
// If the object type is a mapped type { [P in K]: E }, where K is generic, instantiate E using a mapper

0 commit comments

Comments
 (0)