• Category

    Create a copy of an object with a key renamed.

    Time complexity: O(1)

    Space complexity: O(1)

    Type Parameters

    • T
    • K1 extends string | number | symbol
    • K2 extends PropertyKey

    Parameters

    Returns Omit<T, K1 | K2> & Record<K2, T[K1]>

    A shallow-copied object with the key name updated

    Object

    Example

    const object = { a: 1 };

    rename(object, 'a', 'b'); // { b: 1 }