Advanced TypeScript for Harness Builders

14. `as const` Assertions & `satisfies`

Preserve literal types and validate shape without widening.

as const satisfies

File: packages/coding-agent/src/core/keybindings.ts L50-137

export const KEYBINDINGS = {
  "app.interrupt": { defaultKeys: "escape", description: "Cancel or abort" },
  "app.clear": { defaultKeys: "ctrl+c", description: "Clear editor" },
  // ... 30+ entries
} as const satisfies KeybindingDefinitions;
  • as const preserves the exact literal types of every key and value
  • satisfies KeybindingDefinitions validates the shape without widening

File: packages/coding-agent/src/core/keybindings.ts L139-199

const KEYBINDING_NAME_MIGRATIONS = {
  cursorUp: "tui.editor.cursorUp",
  // ...
} as const satisfies Record<string, Keybinding>;

satisfies without as const (for runtime values)

File: packages/ai/src/providers/mistral.ts L129

return streamMistral(model, context, {
  ...base,
  promptMode: shouldUseReasoning ? "reasoning" : undefined,
  reasoningEffort: shouldUseReasoning ? mapReasoningEffort(reasoning) : undefined,
} satisfies MistralOptions);

Validates the object literal matches MistralOptions without changing the inferred type.


Open this chapter inside the full course