Type alias ReplaceKeys<U, T, Y>

ReplaceKeys<U, T, Y>: {
    [K in Keys<U>]: IfExtends<K, T, K extends Keys<Y>
        ? Y[K]
        : never, U[K]>
}

Constructs a new type by replacing keys of type T in object type U with corresponding keys from object type Y.

Type Parameters

  • U

    The original object type.

  • T

    The type of keys to replace.

  • Y

    The object type containing replacement keys.

Example

type Original = {
bar: string;
foo: number;
fooBar: string;
};

type Replacement = ReplaceKeys<Original, 'bar', { bar: number }>;

// Result: { bar: number; foo: number; fooBar: string; }

type AnotherReplacement = ReplaceKeys<Original, 'foo', { foo: boolean }>;

// Result: { bar: string; foo: boolean; fooBar: string; }