/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-contextvariablemap-b353311678e4-contextvariablemap-s0568-c0001.md
ContextVariableMap (2) - hono-docs
ContextVariableMap (2) Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt contextvariablemap Summary...
ContextVariableMap (2)
Source evidence: /Sources/raw/honojshono/honojshono.md Canonical citation: https://hono.dev/llms-full.txt#contextvariablemap
Summary
You can augment the ContextVariableMap interface to define types for context variables globally across your entire application. This is appropriate when a variable is set by middleware that is applied app-wide and is guaranteed to exis...
Content
You can augment the ContextVariableMap interface to define types for context variables globally across your entire application. This is appropriate when a variable is set by middleware that is applied app-wide and is guaranteed to exist in the context.
For example:
declare module 'hono' {
interface ContextVariableMap {
result: string
}
}You can then utilize this in your middleware:
import { createMiddleware } from 'hono/factory'
// ---cut---
const mw = createMiddleware(async (c, next) => {
c.set('result', 'some values') // result is a string
await next()
})In a handler, the variable is inferred as the proper type: