Skip to content

Commit

Permalink
feat(#114): finish IsDeepNonRequired<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGw committed Apr 26, 2024
1 parent f85b154 commit 2891b4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,19 @@ export type DeepNonRequired<T> = T extends UnknownFunction
: {
[K in Keys<T>]+?: IfExtends<T[K], unknown, DeepNonRequired<T[K]>, T[K]>;
};

/**
* Check if all the properties of a given object (nested) are non required
* @returns
* `true` if all the properties are, otherwise `false`
*/
export type IsDeepNonRequired<T> = IfExtends<
T,
DeepNonRequired<T>,
true,
false
>;

/**
* @hidden
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/deep-non-required.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DeepNonRequired,
Primitive,
Maybe,
IsDeepNonRequired,
Nullable,
TestType,
} from 'src';
Expand Down Expand Up @@ -46,3 +47,8 @@ test('_', () => {
const result: TestType<DeepNonRequired<Actual>, Expected, true> = true;
expect(result).toBe(true);
});

test('_', () => {
const result: TestType<IsDeepNonRequired<Expected>, true, true> = true;
expect(result).toBe(true);
});

0 comments on commit 2891b4d

Please sign in to comment.