The type to make deeply readonly.
type PlayerData = {
requestType: string;
timing: { start: number; };
};
const data: DeepReadonly<PlayerData> = {
requestType: 'segment',
timing: { start: 0 },
}
// Reading at any depth is unchanged.
ok(data.requestType === 'segment')
ok(data.timing.start === 0)
// @ts-expect-error - top-level properties are readonly
data.requestType = 'manifest'
// @ts-expect-error - nested properties are readonly too
data.timing.start = 1
Utility type that marks every property of a given type as
readonly, recursively.Readonly<T>stops at the top level, so a nested object remains writable andvalue.nested.field = …still compiles.DeepReadonlyapplies at every depth, including through arrays.Functions keep their type, so callbacks on a value remain callable. Primitives keep their type.