extendClient

function extendClient<TClient, TAdditions>(
    client,
    additions,
): Omit<TClient, keyof TAdditions> & TAdditions;

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.

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

Omit<TClient, keyof TAdditions> & TAdditions

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

ClientPlugin

On this page