Skip to content

Commit

Permalink
feat : _FilterNull, _FulterUndefined type created
Browse files Browse the repository at this point in the history
  • Loading branch information
kakasoo committed Jan 18, 2024
1 parent 8194a83 commit 01d54fc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/types/array.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ import { Equal, ObjectType } from './object.type';
import { Primitive, ReadonlyOrNot } from './primitive.type';

export namespace ArrayType {
export type Filter = any;
export type _FilterNull<AllowNull extends boolean, Target> = [
...(AllowNull extends false ? (Equal<Target, null> extends true ? [] : [Target]) : [Target]),
];

export type _FilterUndefined<AllowUndefined extends boolean, Target> = [
...(AllowUndefined extends false ? (Equal<Target, undefined> extends true ? [] : [Target]) : [Target]),
];

export type Filter<
T extends ReadonlyOrNot<any[]>,
AllowNull extends boolean,
AllowUndefined extends boolean,
> = T extends [infer First, ...infer Rest]
? [..._FilterNull<AllowNull, First>, Filter<Rest, AllowNull, AllowUndefined>]
: [];

/**
* Get length of tuple or string literal type.
Expand Down

0 comments on commit 01d54fc

Please sign in to comment.