Last active
May 2, 2023 16:05
-
-
Save tolotrasmile/3e0e99701945b68ce606b6e27f55473c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/total-typescript/shoehorn | |
export type NoInfer<T> = [T][T extends any ? 0 : never]; | |
export type DeepPartial<T> = T extends (...args: any[]) => unknown | |
? T | undefined | |
: T extends object | |
? T extends ReadonlyArray<infer ItemType> | |
? ItemType[] extends T | |
? readonly ItemType[] extends T | |
? ReadonlyArray<DeepPartial<ItemType | undefined>> | |
: Array<DeepPartial<ItemType | undefined>> | |
: DeepPartialObject<T> | |
: DeepPartialObject<T> | |
: T; | |
export type DeepPartialObject<ObjectType extends object> = { | |
[KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>; | |
}; | |
export function mock<T>(mock: DeepPartial<NoInfer<T>>): T { | |
return mock as T | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment