Created
December 10, 2019 21:39
-
-
Save dancrumb/8c6a7be234341164ace00420bce1d6f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export type JSONType<T> = T extends Date | |
? string | |
: T extends number | |
? number | |
: T extends boolean | |
? boolean | |
: T extends string | |
? string | |
: T extends Array<infer F> | |
? __JSONNonArrayType<F>[] | |
: T extends {} | |
? __JSONObjectType<WithoutMethods<T>> | |
: never; | |
type __JSONNonArrayType<T> = T extends number | |
? number | |
: T extends boolean | |
? boolean | |
: T extends string | |
? string | |
: T extends {} | |
? __JSONObjectType<WithoutMethods<T>> | |
: never; | |
type __JSONObjectType<T extends object> = { | |
[K in keyof T]: T[K] extends Optional<infer U> | |
? JSONType<U> | undefined | |
: JSONType<T[K]>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment