/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-contextvariablemap-b353311678e4-contextvariablemap-s0568-c0000.md

ContextVariableMap (1) - hono-docs

ContextVariableMap (1) Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt contextvariablemap Summary...

ContextVariableMap (1)

Source evidence: /Sources/raw/honojshono/honojshono.md Canonical citation: https://hono.dev/llms-full.txt#contextvariablemap

Summary

::: warning ContextVariableMap adds types globally to all contexts, regardless of whether the middleware that sets the variable has actually run. This means c.get('result') will appear type-safe even in handlers where your middle...

Content

::: warning ContextVariableMap adds types globally to all contexts, regardless of whether the middleware that sets the variable has actually run. This means c.get('result') will appear type-safe even in handlers where your middleware was never registered, potentially hiding undefined bugs at runtime.

Take a look at the following example:

declare module 'hono' {
  interface ContextVariableMap {
    result: string
  }
}

const mw = createMiddleware(async (c, next) => {
  c.set('result', 'some values')
  await next()
})

const app = new Hono()

// handler uses the middleware
app.get('/foo', mw, (c) => {
  const val = c.get('result') // ✅ val is a string and typed as such, as expected
})

// handler doesn't use the middleware
app.get('/bar', (c) => {
  const val = c.get('result') // ❌ val is undefined but typed as a string, which can lead to runtime errors
})

:::

Kinic Wiki
Loading knowledge node
Details

Identity

database
db_23dhmsxlhukv
database_id
db_23dhmsxlhukv
path
/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-contextvariablemap-b353311678e4-contextvariablemap-s0568-c0000.md
kind
directory
role
markdown_note
children
0

Metadata

created_at
virtual
updated_at
virtual
etag
virtual
metadata_json
{}

Lint Hints

No lightweight warnings.

Outgoing Links

No outgoing links indexed.

Incoming Links

Select a file node to inspect backlinks.

Raw Source

No raw source path inferred.