Skip to content

Instantly share code, notes, and snippets.

@xiaoxiangmoe
Created July 13, 2019 05:34
Show Gist options
  • Save xiaoxiangmoe/b3882aa798f03cb9924d293cf74514be to your computer and use it in GitHub Desktop.
Save xiaoxiangmoe/b3882aa798f03cb9924d293cf74514be to your computer and use it in GitHub Desktop.
DeepReadonly
// tslint:disable
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
type DeepReadonlyObject<T> = T extends Function
? T
: { readonly [P in keyof T]: DeepReadonly<T[P]> };
export type DeepReadonly<T> = T extends any[]
? DeepReadonlyArray<T[number]>
: T extends object
? DeepReadonlyObject<T>
: T;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment