Recursively make every property of T readonly.
T
readonly
Used to make state passed into actions/selectors uneditable at compile time, so s.player.x = 10 is a TypeScript error and consumers are nudged toward immutable updates.
s.player.x = 10
Functions, arrays, maps, sets, and primitives are handled.
type State = { player: { x: number; y: number } };type Readonly = DeepReadonly<State>;// ^? { readonly player: { readonly x: number; readonly y: number } } Copy
type State = { player: { x: number; y: number } };type Readonly = DeepReadonly<State>;// ^? { readonly player: { readonly x: number; readonly y: number } }
Recursively make every property of
Treadonly.Used to make state passed into actions/selectors uneditable at compile time, so
s.player.x = 10is a TypeScript error and consumers are nudged toward immutable updates.Functions, arrays, maps, sets, and primitives are handled.