Skip to content

Instantly share code, notes, and snippets.

@imkrish
Last active April 27, 2019 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkrish/6c942508c57e5a04e6df1be288424ccd to your computer and use it in GitHub Desktop.
Save imkrish/6c942508c57e5a04e6df1be288424ccd to your computer and use it in GitHub Desktop.
type DeepReadonlyObject<T> = { readonly [K in keyof T]: DeepReadonly<T[K]> };
type DeepReadonly<T> = T extends (infer E)[][]
? ReadonlyArray<ReadonlyArray<DeepReadonlyObject<E>>>
: T extends (infer E)[]
? ReadonlyArray<DeepReadonlyObject<E>>
: T extends object
? DeepReadonlyObject<T>
: T;
interface ITodo {
task: string;
done: boolean;
}
interface IRootState {
userId: string;
showCompletedOnly: boolean;
todoTypes: string[];
todos: ITodo[];
iconGrid: string[][];
}
type ReadonlyRootState = DeepReadonly<IRootState>;
let rootState: ReadonlyRootState; // Typescript service will prevent this variable from mutation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment