Type definitions

Request contexts, Worker contexts, common results, and domain types in the default template.

The default template's shared types are primarily defined in src/types.ts and src/ctx/. Each application module keeps its own input types, output types, and data models rather than placing them all in a single global type file.

Variables

Variables defines the context variables available through c.get(), c.set(), and c.var during a Hono request. It is defined in src/types.ts.

Prop

Type

Ctx

type Ctx = Context<{
    Bindings: CloudflareBindings;
    Variables: Variables;
}>;

Ctx is the Hono Context type used throughout the default template. Read Cloudflare resources and runtime variables through c.env, and request context variables through c.var or c.get().

WorkerCtx

WorkerCtx, defined in src/ctx/create.ts, is the runtime context shared by HTTP, Queue, Cron, and Durable Object Alarm handlers.

Prop

Type

createWorkerCtx

Creates a WorkerCtx from a Hono Context or fields provided by a non-HTTP entry point. The fetch entry point passes a Hono Context. The queue, scheduled, and alarm entry points pass env, logger, locale, tr, and i18nCtx.

resolveFetchWorkerCtx

Accepts Context | WorkerCtx. If the argument is already a WorkerCtx, returns it directly. Otherwise, creates a new WorkerCtx for the fetch entry point.

getWorkerCtx

getWorkerCtx, defined in src/ctx/get.ts, creates a complete context for Queue, Cron, and Alarm entry points. When locale is omitted, it uses the default language from config/i18n.ts. When runtime is omitted, it uses queue.

Use WorkerCtx only within the current invocation

Do not cache the return value of getWorkerCtx() at module scope. A Worker isolate may handle multiple invocations in succession. Each invocation must use its own logger, language, and runtime information.

Common result types

These types are all defined in src/types.ts.

SuccessResult<T>

Prop

Type

FailureResult

Prop

Type

FnResult<T>

SuccessResult<T> | FailureResult provides a common success-or-failure return type for services and other internal functions.

APIResponse<T>

The API response type. Successful responses have the same type as SuccessResult<T>. Failed responses must include error, which the client uses to look up the error message in the appropriate language.

isSuccessResult

Narrows APIResponse<T> to SuccessResult<T> based on success === true.

Type locations

Type categoryLocation
Configuration inputs and validation rulessrc/libs/config/schemas/
Cloudflare bindingsworker-configuration.d.ts
API request parametersThe corresponding src/api/**/schema.ts or route file
Accounts, authentication, and sessionssrc/core/services/auth/types.ts, src/core/services/session/types.ts
Roles, entitlements, capabilities, and subjectssrc/core/services/access/**/types.ts
Paymentssrc/core/modules/payment-v1/types.ts and its submodules
Affiliate programsrc/core/services/affiliate/**/types.ts
Reactionsrc/core/reaction/types.ts and the definition files for each Event and Command
Raw database records and SQL query resultsType or DAO files under src/core/db/
Repository operation inputs, results, and data transformationsThe corresponding module under src/core/repositories/
Domain typesThe domain module that owns the concept
API request and response DTOsThe corresponding endpoint module under src/api/

npm run cf-typegen generates worker-configuration.d.ts from wrangler.jsonc and environment variables. Do not edit it directly.