Zod 4 (and all other Standard Schema support) is available as a release candidate `3.53.0-rc.1`
ts-rest
Contract

Type Helpers

Contracts pretty complex, so we expose some helpers to let you pull out the useful parts for your app

Client Helpers

ClientInferRequest

Extracts the exact request type that the client needs to send, including any optional fields and client-specific options like fetchOptions. This is useful when you need to type function parameters or variables that will be passed to the ts-rest client.


import {  } from '@ts-rest/core';

type Request = <typeof .>;
type Request = {
    cache?: RequestCache | undefined;
    fetchOptions?: FetchOptions | undefined;
    params: {
        id: string;
    };
    extraHeaders?: Record<string, string> | undefined;
    overrideClientOptions?: Partial<OverrideableClientArgs> | undefined;
}

ClientInferResponseBody

Extracts the response body type for a specific status code as the client will receive it. Perfect for typing React component props or variables that store API response data.


import {  } from '@ts-rest/core';

type ResponseBody = <typeof ., 200>;
type ResponseBody = {
    name: string;
}

ClientInferResponses

Extracts all possible response types that the client can receive, including status codes and headers. Useful for handling all response scenarios in error handling or response processing logic.


import {  } from '@ts-rest/core';

type Responses = <typeof .>;
type Responses = {
    status: 200;
    body: {
        name: string;
    };
    headers: Headers;
} | {
    status: 100 | 101 | 102 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308 | 400 | 401 | 402 | ... 33 more ... | 511;
    body: unknown;
    headers: Headers;
}

Server Helpers

ServerInferRequest

Extracts the request type as the server will receive it, including any Zod transformations applied to path params or query strings. Essential for typing Lambda handlers, route handlers, or middleware functions that process incoming requests.


import {  } from '@ts-rest/core';

type Request = <typeof .>;
type Request = {
    params: {
        id: string;
    };
}

ServerInferResponseBody

Extracts the response body type that the server needs to return for a specific status code. Useful for typing service functions or database query results that will be returned as API responses.


import {  } from '@ts-rest/core';

type ResponseBody = <typeof ., 200>;
type ResponseBody = {
    name: string;
}

ServerInferResponses

Extracts all possible response types that the server can return, including status codes and any response metadata. Perfect for typing handler return values or functions that need to return different response types based on business logic.


import {  } from '@ts-rest/core';

type Responses = <typeof .>;
type Responses = {
    status: 200;
    body: {
        name: string;
    };
} | {
    status: 100 | 101 | 102 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | ... 30 more ... | 511;
    body: unknown;
}