Skip to content

ContextVariableMap

reference
1 min readUpdated

Kind: Interface

Source: src/context.ts

Interface for context variable mapping.

ContextVariableMap defines the named values stored in a context. Context writers add or update entries in the map, while context consumers read entries by variable name.

Diagram

mermaid
graph LR
  Writer[Context Writer] --> Map[ContextVariableMap]
  Map --> Reader[Context Consumer]

Usage

ts
function readContextValue(
  variables: ContextVariableMap,
  name: string,
) {
  return variables[name];
}

const variables: ContextVariableMap = {
  locale: "en-US",
  userName: "Alex",
};

const locale = readContextValue(variables, "locale");

AI Coding Instructions

  • Type dynamically keyed context values as ContextVariableMap.
  • Keep variable names consistent between context writers and consumers.
  • Handle missing values when reading entries from the map.
  • Update context creation and lookup code together when adding a new variable name.

Was this page helpful?

Download as PDF
ContextVariableMap — Hono (narrator proof)