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 Parameter | Default type | Description |
---|---|---|
| ‐ | Items to filter |
| ‐ | Type to filter out |
| [] | ‐ |
Example
type Result = Filter<['a', 'b', 'c'], 'b'>
// ^? type Result = ['a', 'c']
Defined
@nilfoundation/niljs/src/types/utils.ts:77