extendClient

function extendClient<TClient, TAdditions>(
    client,
    additions,
): {
    [K in string | number | symbol]: (Omit<TClient, keyof TAdditions> &
        TAdditions)[K];
};

Extends a client object with additional properties, preserving property descriptors (getters, symbol-keyed properties, and non-enumerable properties) from both objects.

Use this inside plugins instead of plain object spread ({...client, ...additions}) when the client may carry getters or symbol-keyed properties that spread would flatten or lose. When the same key exists on both, additions wins.

The return type is an ExtendedClient, which flattens the merged shape into a single object literal so chained extendClient calls do not accumulate nested Omit<...> wrappers in editor tooltips and error messages.

Type Parameters

Type ParameterDescription
TClient extends objectThe type of the original client.
TAdditions extends objectThe type of the properties being added.

Parameters

ParameterTypeDescription
clientTClientThe original client object to extend.
additionsTAdditionsThe properties to add or override on the client.

Returns

{ [K in string | number | symbol]: (Omit<TClient, keyof TAdditions> & TAdditions)[K] }

A new object combining both, with additions taking precedence on conflicts.

Example

function rpcPlugin(endpoint: string) {
    return <T extends object>(client: T) =>
        extendClient(client, { rpc: createSolanaRpc(endpoint) });
}

See

On this page