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 dedicatedtypes/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
Handler and middleware types
Import the exported types fromblaze 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 toreq — 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
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 }.
Recommended tsconfig.json
Use these settings to get full type coverage for Blaze and the Cloudflare Workers runtime:tsconfig.json
Type-only imports
Useimport 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.