Skip to content

Instantly share code, notes, and snippets.

@riivanov
Created February 7, 2023 22:51
Show Gist options
  • Save riivanov/0e5f7ae42ddecd666aba3124a691955f to your computer and use it in GitHub Desktop.
Save riivanov/0e5f7ae42ddecd666aba3124a691955f to your computer and use it in GitHub Desktop.
Recursive Type Example
type DeepReadonlyObject<T> = { readonly [K in keyof T]: DeepReadonly<T[K]> };
type DeepReadonly<T> = T extends (infer E)[] ?
ReadonlyArray<ReadonlyArray<DeepReadonlyObject<E>>> :
T extends object ? DeepReadonlyObject<T> :
T;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment