utilitypes-ts
    Preparing search index...

    Type Alias MakeMutable<T, K>

    MakeMutable: T extends T
        ? Omit<T, K> & { -readonly [Key in Extract<K, keyof T>]: T[Key] }
        : never

    Makes specified keys K mutable in each member of a union T.

    This distributes over unions, ensuring each member is processed individually. Only keys that exist in each member are affected.

    Type Parameters

    • T

      The target type (can be a union)

    • K extends UnionKey<T> = UnionKey<T>

      Keys to make mutable (defaults to all union keys)

    type Result = MakeMutable<{ readonly a: string; readonly b: number }>;
    // ^?
    // { a: string; b: number }
    type Result = MakeMutable<{ readonly a: string } | { readonly b: number }>;
    // ^?
    // { a: string } | { b: number }
    type Result = MakeMutable<{ readonly a: string } | { readonly b: number }, "a">;
    // ^?
    // { a: string } | { readonly b: number }