InjectClient
Recursively walks a schema and rebuilds every
Request
leaf with the SDK's actual client
type injected into the
Client
generic slot. Lets users omit
client
from their
RequestModel<{...}>
declarations - the SDK fills it in from the client passed to
createSdk(client)
.
Non-Request leaves (primitive values, plain types) are passed through unchanged. Nested schema objects are recursed into. Depth is guarded at 10 levels to keep the type checker within reasonable bounds.
Import
import { InjectClient } from "@hyper-fetch/core"
Source
Package
Preview
type InjectClient<T,TClient,Depth> = Depth[length] extends 10 ? T : T extends RequestInstance ? Request<ExtractResponseType<T>, ExtractPayloadType<T>, ExtractQueryParamsType<T>, ExtractLocalErrorType<T>, ExtractEndpointType<T> extends string ? ExtractEndpointType<T> : string, TClient, ExtractHasPayloadType<T> extends boolean ? ExtractHasPayloadType<T> : false, ExtractHasParamsType<T> extends boolean ? ExtractHasParamsType<T> : false, ExtractHasQueryParamsType<T> extends boolean ? ExtractHasQueryParamsType<T> : false, ExtractMutationContextType<T>> : T extends Record<string, any> ? { [ K in keyof T]: InjectClient<T[K], TClient, [...Depth, unknown]> } : T;
