Type alias DeepMutable<T>

DeepMutable<T>: T extends UnknownFunction
    ? T
    : {
        -readonly [K in Keys<T>]: T[K] extends unknown
            ? DeepMutable<T[K]>
            : T[K]
    }

A type that recursively mutates all the proprties within a given object type T.

Type Parameters

  • T

Example

type Actual = {
readonly a: () => 1;
readonly x: string;
readonly s: {
readonly q: Nullable;
readonly s: {
readonly i: {
readonly x: {
readonly o: Maybe<Primitive>;
readonly n: Falsy;
};
readonly e: 'foo';
};
};
};
};

type Expected = {
a: () => 1;
x: string;
s: {
q: Nullable;
s: {
i: {
x: {
o: Maybe<Primitive>;
n: Falsy;
};
e: 'foo';
};
};
};
};
type T = DeepMutable<Actual>; // T Results in: Expected