Skip to main content
Blaze propagates your Env generic through the entire application — no casting, no any. The moment you write createApp<Env>(), every req.env access, every req.params lookup, and every handler signature becomes fully typed. Blaze exports Handler, ErrorHandler, Middleware, NextFunction, and CookieOptions as type-only exports, and BlazeRequest, BlazeResponse, and BlazeError as concrete class exports, so you can annotate standalone functions and augment request types anywhere in your codebase.

Defining your Env type

Create a dedicated types/env.ts that mirrors your wrangler.toml bindings exactly. Pass it as the generic argument to createApp<Env>() — the type flows to every handler automatically.
types/env.ts
src/index.ts
Keep types/env.ts as the single source of truth for your bindings. When you add or rename a binding in wrangler.toml, update this file first — TypeScript will flag every stale reference immediately.

Handler and middleware types

Import the exported types from blaze to annotate standalone handler and middleware functions. This is especially useful for handlers that live in separate route files.

Augmenting BlazeRequest

Middleware often attaches custom properties to req — things like req.user after auth or req.id from the requestId middleware. Declare these additions by augmenting the BlazeRequest interface in a .d.ts file so TypeScript knows about them everywhere.
types/blaze.d.ts
Place this file anywhere TypeScript picks it up — types/blaze.d.ts works well, and you can reference it with "include": ["src", "types"] in tsconfig.json. When to use augmentation: every time a middleware sets a property on req that downstream handlers need to read. Without the augmentation, TypeScript will error on req.user even though the property exists at runtime. With it, req.user is typed everywhere with zero extra imports.
The augmentation applies globally. If you access req.id in a route that runs before the requestId middleware, TypeScript won’t warn you — that’s a runtime concern. Use middleware ordering to enforce correctness.

Typed route params

req.params is typed based on your route pattern. Named segments — :id, :slug, :org — become string-typed keys on the params object. Wildcard segments (*) become { '*': string }.
Use these settings to get full type coverage for Blaze and the Cloudflare Workers runtime:
tsconfig.json

Type-only imports

Use import type for all Blaze type imports. Because types are erased at compile time, import type has zero runtime cost and ensures the import is never accidentally bundled as a value.
This is especially important for middleware types that are only used in function signatures — the bundler can tree-shake freely and your Worker’s boot time stays minimal.