Types
CloudContext
Hono Context pre-typed with CloudEnv. This is the type of the c parameter in all route handlers and middleware.
import type { CloudContext } from 'void';CloudEnv
Hono environment type for Void workers. Extends Hono's Env with Cloudflare bindings and context variables.
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:
interface CloudContextVariables {
user: AuthUser | null;
session: AuthSession | null;
[key: string]: unknown;
}Augmentation example:
declare module 'void' {
interface CloudContextVariables {
requestId: string;
}
}
// c.get("requestId") → stringSee Type Safety for details.
TypedHandler<V, R>
The return type of defineHandler, with validator types (V) and the handler’s return type (R).
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.
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.
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:
import { routeUrl } from 'void/routes';
routeUrl('/users/:id', {
params: { id: 42 },
query: { tab: 'activity' },
hash: 'details',
});
// /users/42?tab=activity#details| Option | Type | Description |
|---|---|---|
params | Route-specific | Required for dynamic routes. Each parameter accepts a string or number. |
query | RouteQuery | Query parameters. Arrays become repeated keys; null and undefined are omitted. |
hash | string | URL 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:
| Type | Description |
|---|---|
RoutePathMap | Generated map of page, HTTP, and WebSocket route patterns to their parameter names. |
RoutePath | Union of the known route patterns in RoutePathMap. |
PagePathMap | Generated map of page patterns to their parameter names. |
PagePath | Union 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. |
RouteUrl | The URL of one of your routes, returned by routeUrl(). string unless typedRoutes is on. |
Href | A RouteUrl, a same-page query or hash, or an external URL. string unless typedRoutes is on. |
RouteUrlInput | Href, URL, or RouteDestination; accepted by router navigation methods. |
RouteQuery | Query keys mapped to RouteQueryValue or readonly arrays of those values. |
RouteQueryValue | string, number, boolean, null, or undefined. |
typedRoutes is routing.typedRoutes. See Checked URL strings.