Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Refactor primitive support (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
malash authored and yungsters committed Apr 4, 2019
1 parent d9664a5 commit 396aadb
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/idx/src/idx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export type IDXOptional<T> = T | null | undefined;
* DeepRequiredObject
* Nested object condition handler
*/
type DeepRequiredObject<T> = T extends object
? {[P in keyof T]-?: DeepRequired<NonNullable<T[P]>>}
: T;
type DeepRequiredObject<T extends object> = {
[P in keyof T]-?: DeepRequired<NonNullable<T[P]>>
};

/**
* Function that has deeply required return type
Expand All @@ -34,18 +34,16 @@ type FunctionWithRequiredReturnType<
type DeepRequired<T> = T extends any[]
? DeepRequiredArray<T[number]>
: T extends (...args: any[]) => any
? FunctionWithRequiredReturnType<T>
: T extends object ? DeepRequiredObject<T> : T;
? FunctionWithRequiredReturnType<T>
: T extends object
? DeepRequiredObject<T>
: T;

/**
* UnboxDeepRequired
* Unbox type wrapped with DeepRequired
*/
type UnboxDeepRequired<T> = T extends DeepRequiredArray<infer R>
? Array<R>
: T extends (...args: infer A) => DeepRequired<infer R>
? (...args: A) => UnboxDeepRequired<R>
: T extends DeepRequiredObject<infer R> ? R : T;
type UnboxDeepRequired<T> = T extends DeepRequired<infer R> ? R : T;

/**
* Traverses properties on objects and arrays. If an intermediate property is
Expand Down

0 comments on commit 396aadb

Please sign in to comment.