Skip to content
Built with

Types ​

SDK Reference

This page lists the shared TypeScript types used in handlers, pages and config.

On this pageType a handler's context and environment · Type head descriptors and route maps · Find where each type comes from

CloudContext ​

A Hono Context typed with CloudEnv. It is the type of c in every route handler and middleware.

ts
import type { CloudContext } from 'void';

CloudEnv ​

The Hono environment type for SDK Workers. It extends Hono's Env with Cloudflare bindings and context variables.

ts
interface CloudEnv extends Env {
  Bindings: {
    DB: D1Database;
    KV: KVNamespace;
    STORAGE: R2Bucket;
    AI: Ai;
    SANDBOX: DurableObjectNamespace<import('void/sandbox').VoidPlatformSandbox>;
    [key: string]: unknown;
  };
  Variables: CloudContextVariables;
}

CloudContextVariables ​

The type of context variables for c.set() and c.get(). Augment it to add typed variables that every middleware and handler can read:

ts
interface CloudContextVariables {
  user: AuthUser | null;
  session: AuthSession | null;
  [key: string]: unknown;
}

Augmentation example:

ts
declare module 'void' {
  interface CloudContextVariables {
    requestId: string;
  }
}

// c.get("requestId") → string

See Type Safety for details.

TypedHandler<V, R> ​

The return type of defineHandler. V holds the validator types and R the handler's return type.

ts
interface TypedHandler<V extends ValidatorSlots = {}, R = unknown> {
  (c: CloudContext): Promise<Response> | Response | unknown;
  readonly __validators: V; // type-level only
  readonly __output: R; // type-level only
}

HeadDescriptor ​

The shape of the page head metadata that defineHead returns. All fields are optional.

ts
interface HeadDescriptor {
  title?: string;
  meta?: Array<{ name?: string; property?: string; content?: string; charset?: string }>;
  link?: Array<{ rel: string; href: string; [key: string]: string | undefined }>;
  script?: Array<{ src?: string; innerHTML?: string; [key: string]: string | undefined }>;
  htmlAttrs?: Record<string, string>;
  bodyAttrs?: Record<string, string>;
}

RouteMap ​

Generated route types for the typed fetch client. They hold each route's methods, inputs and outputs.

ts
import type { RouteMap } from 'void/routes';

Next steps ​

implemented.stream AI