Skip to content

Instantly share code, notes, and snippets.

@silvio2402
Created August 28, 2023 17:35
Show Gist options
  • Save silvio2402/128508541bcd78eb9cdacc73c2923f9b to your computer and use it in GitHub Desktop.
Save silvio2402/128508541bcd78eb9cdacc73c2923f9b to your computer and use it in GitHub Desktop.
Deserialized Type TypeScript
type Deserialized<T> = T extends Array<infer U>
? Array<Deserialized<U>>
: T extends string | number | boolean
? T
: "toJSON" extends keyof T
? T["toJSON"] extends (...args: any) => any
? ReturnType<T["toJSON"]>
: { [K in keyof T]: Deserialized<T[K]> }
: { [K in keyof T]: Deserialized<T[K]> };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment