Use filter instead of unnecessary laziness

This commit is contained in:
Nathan Shively-Sanders 2018-01-12 14:56:50 -08:00
parent d74820d519
commit f1622f0dc6

View File

@ -8389,18 +8389,11 @@ namespace ts {
}
// Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or
// more mapped types with a template type `never`, '(U & V & { [P in T]: never })[K]', return a
// transformed type that removes the never-mapped type: '(U & V)[K]'. This mirrors what would happen
// transformed type that removes the never-mapped type: '(U & V)[K]'. This mirrors what would happen
// eventually anyway, but it easier to reason about.
if (objectType.flags & TypeFlags.Intersection && isGenericObjectType(objectType) && some((<IntersectionType>objectType).types, isMappedTypeToNever)) {
let nonNeverTypes: Type[];
for (const t of (<IntersectionType>objectType).types) {
if (!isMappedTypeToNever(t)) {
(nonNeverTypes || (nonNeverTypes = [])).push(t);
}
}
if (nonNeverTypes) {
return getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType);
}
const nonNeverTypes = filter((<IntersectionType>objectType).types, t => !isMappedTypeToNever(t));
return getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType);
}
// If the object type is a mapped type { [P in K]: E }, where K is generic, instantiate E using a mapper