From f1622f0dc6b75a727ce8f0c2e2ef05a33dd31bbd Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 12 Jan 2018 14:56:50 -0800 Subject: [PATCH] Use filter instead of unnecessary laziness --- src/compiler/checker.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1a5cc357c78..811fe868f96 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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((objectType).types, isMappedTypeToNever)) { - let nonNeverTypes: Type[]; - for (const t of (objectType).types) { - if (!isMappedTypeToNever(t)) { - (nonNeverTypes || (nonNeverTypes = [])).push(t); - } - } - if (nonNeverTypes) { - return getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType); - } + const nonNeverTypes = filter((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