Skip to main content

Type Alias: Filter<T, P, Acc>

type 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

Type ParameterDefault typeDescription

T extends readonly unknown[]

Items to filter

P

Type to filter out

Acc extends readonly unknown[]

[]

Example

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

Defined

@nilfoundation/niljs/src/types/utils.ts:77