Route types (GetRoute & PostRoute)
@toapi/client exports two helper types that describe the callable signature of a single route method. You rarely need them when calling the client directly — the full Client<Routes> type already infers everything — but they are handy when writing generic wrappers, adapters, or utilities that accept “a GET-style” or “a POST-style” route callable.
GetRoute
Section titled “GetRoute”export type GetRoute<R, Q = undefined> = Q extends undefined ? (query?: {}, req?: RequestInit) => Promise<R> & Observable<R> : (query: Q, req?: RequestInit) => Promise<R> & Observable<R>;Describes a GET callable that resolves to R and is subscribable (Observable<R>).
R— the response type.Q(optional) — the query-parameter type. When omitted (undefined), the query argument is optional; when provided, it becomes required.
import type { GetRoute } from "@toapi/client";
// A route returning User[] with no required querytype ListUsers = GetRoute<User[]>;
// A route returning User[] with a required { active: boolean } querytype SearchUsers = GetRoute<User[], { active: boolean }>;PostRoute
Section titled “PostRoute”export type PostRoute<R, Q = unknown, B = unknown> = ( query: Q | FormData, body: B | FormData, req?: RequestInit,) => Promise<R>;Describes a mutation callable that resolves to R.
R— the response type.Q(optional) — the query-parameter type.B(optional) — the request-body type.
import type { PostRoute } from "@toapi/client";
type CreateUser = PostRoute<User, undefined, { name: string }>;