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 stays writable andvalue.nested.field = …still compiles. This applies at every depth, including through arrays.Functions are left unchanged so callbacks carried on a value stay callable, and primitives are returned as they are.