Skip to content
brought to you byVoidZero

Types ​

CloudContext ​

Hono Context pre-typed with CloudEnv. This is the type of the c parameter in all route handlers and middleware.

ts
import type { CloudContext } from 'void';

CloudEnv ​

Hono environment type for Void workers. 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>;
    ASSETS: { fetch(request: Request): Promise<Response> };
    [key: string]: unknown;
  };
  Variables: CloudContextVariables;
}

CloudContextVariables ​

The context variables type used by c.set() / c.get(). Augment this interface to add typed variables that flow through all middleware and handlers:

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, with validator types (V) and the handler’s return type (R).

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 ​

Shape of page head metadata returned by defineHead. 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 used by the typed fetch client. Contains each route’s methods, inputs, and outputs.

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

void/routes ​

routeUrl(path, options?) ​

Build a relative URL string from a known page, HTTP, or WebSocket route pattern:

ts
import { routeUrl } from 'void/routes';

routeUrl('/users/:id', {
  params: { id: 42 },
  query: { tab: 'activity' },
  hash: 'details',
});
// /users/42?tab=activity#details
OptionTypeDescription
paramsRoute-specificRequired for dynamic routes. Each parameter accepts a string or number.
queryRouteQueryQuery parameters. Arrays become repeated keys; null and undefined are omitted.
hashstringURL fragment, such as 'details' or '#details'.

Static routes accept optional query and hash options. Pass raw parameter values for URL encoding. Catch-all parameters preserve / separators between segments. Invalid or missing path parameters throw a TypeError.

Use the returned RouteUrl with Link, <a>, and c.redirect(). See Typed URLs and Navigation for setup and examples.

Route types ​

Import these types from void/routes:

TypeDescription
RoutePathMapGenerated map of page, HTTP, and WebSocket route patterns to their parameter names.
RoutePathUnion of the known route patterns in RoutePathMap.
PagePathMapGenerated map of page patterns to their parameter names.
PagePathUnion of the page patterns in PagePathMap; accepted by useParams().
PageParams<P>The params page P receives, such as { id: string } for /users/:id.
RouteOptions<P>Options for a route pattern P, including its required params, optional query, and hash.
RouteDestination<P>{ pathname: P } with RouteOptions<P>. Defaults to all known routes when P is omitted.
RouteUrlThe URL of one of your routes, returned by routeUrl(). string unless typedRoutes is on.
HrefA RouteUrl, a same-page query or hash, or an external URL. string unless typedRoutes is on.
RouteUrlInputHref, URL, or RouteDestination; accepted by router navigation methods.
RouteQueryQuery keys mapped to RouteQueryValue or readonly arrays of those values.
RouteQueryValuestring, number, boolean, null, or undefined.

typedRoutes is routing.typedRoutes. See Checked URL strings.