CML
    Preparing search index...

    Type Alias DeepReadonly<T>

    DeepReadonly: T extends (...args: never[]) => unknown
        ? T
        : T extends readonly (infer U)[]
            ? readonly DeepReadonly<U>[]
            : T extends object ? { readonly [P in keyof T]: DeepReadonly<T[P]> } : T

    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 and value.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.

    Type Parameters

    • T

      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