Type alias Filter<T, P, Acc>

Filter<T, P, Acc>: T extends readonly [infer F, ...(infer Rest extends readonly unknown[])]
    ? [F] extends [P]
        ? Filter<Rest, P, [...Acc, F]>
        : Filter<Rest, P, Acc>
    : readonly [...Acc]

Filters out all members of T that are not P

Type Parameters

  • T extends readonly unknown[]

    Items to filter

  • P

    Type to filter out

  • Acc extends readonly unknown[] = []

Returns

Filtered items

Example

type Result = Filter<['a', 'b', 'c'], 'b'>
// ^? type Result = ['a', 'c']

Generated using TypeDoc