-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtypes.ts
More file actions
20 lines (18 loc) · 913 Bytes
/
types.ts
File metadata and controls
20 lines (18 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export type NoInfer<T> = [T][T extends any ? 0 : never];
/**
* Adapted from type-fest's PartialDeep
*/
export type PartialDeep<T> = T extends (...args: infer P) => infer R
? ((...args: P) => PartialDeep<R> | void) & PartialDeepObject<T> | PartialDeepObject<T> | undefined
: T extends object
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
? ItemType[] extends T // Test for arrays (non-tuples) specifically
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
? ReadonlyArray<PartialDeep<ItemType | undefined>>
: Array<PartialDeep<ItemType | undefined>>
: PartialDeepObject<T> // Tuples behave properly
: PartialDeepObject<T>
: T;
export type PartialDeepObject<ObjectType extends object> = {
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>;
};