qbit-rpc
    Preparing search index...

    Type Alias ClientSatisfies<Copy>

    ClientSatisfies: {
        -readonly [K in keyof Copy]-?: K extends keyof QbitRpcClient
            ? Exclude<Copy[K], undefined | null> extends (
                ...args: infer Args,
            ) => infer Result
                ? QbitRpcClient[K] extends (
                    ...args: infer Params,
                ) => infer ClientResult
                    ?
                        | ([ClientResult] extends [Result] ? never : "returns")
                        | (
                            [Args] extends [Params]
                                ? [UndeclaredKeys<(...), (...)>] extends [never]
                                    ? never
                                    : "parameters"
                                : "parameters"
                        )
                    : "type"
                : [QbitRpcClient[K]] extends [
                    {} extends Pick<Copy, K> ? Exclude<Copy[K], undefined> : Copy[K],
                ]
                    ? never
                    : "type"
            : {} extends Pick<Copy, K> ? never : "missing"
    } extends infer Reasons
        ? {
            [K in keyof Reasons as [Reasons[K]] extends [never] ? never : K]: Reasons[K]
        } extends infer Mismatches
            ? {} extends Mismatches ? true : Mismatches
            : never
        : never

    true when QbitRpcClient fits Copy, an interface a consumer declares for the client, strictly enough that every call Copy allows is one the client takes. Otherwise an object with each member of Copy that does not fit, and why:

    • missing: the client has no such member. A member optional in Copy (confirmChain?()) may be missing; check Required<Copy> to require it.
    • returns: what the client's method returns is not assignable to what Copy's returns.
    • parameters: Copy allows arguments the client does not take. They are compared both ways: the arguments Copy allows must be assignable to the client's parameters, compared strictly rather than bivariantly, as TypeScript compares methods; and they may hold no key, at any depth, that the client's parameter there does not declare (UndeclaredKeys). So call options (signal, timeoutMs) declared in a method's own options do not fit: the client takes them in a separate, last argument, and refuses them in the options with a TypeError.
    • type: a member that is not a method has a type the client's is not assignable to, or one of the two is a method and the other is not.

    Limits, where TypeScript gives the type nothing to compare:

    • Overloads: only the last signature of an overloaded member is checked. Declare one signature per member.
    • Generic methods: a generic signature is compared at its constraints, so a copy's generic method can pass where a call through it would not, and the client's generic batch reports returns for a copy that specializes it. Declare copies without type parameters.
    • Outpoints: lockUnspent and unlockUnspent accept a typed result with its extra fields at run time, but declare { txid, vout }; a copy that declares the extras reports parameters.

    Check it in the consumer's type tests, which its CI compiles:

    import type { ClientSatisfies } from '@qbit-oss/rpc'

    true satisfies ClientSatisfies<CoreRpc>

    Type Parameters

    • Copy extends object