SayKit
Guides

Typed messages

How translation file imports are typed, and why the type is generic

Compiling writes a declaration beside every locale module, so import en from './locales/en.js' type-checks:

src/locales/en.d.ts
import type { Message } from 'saykit';

declare const messages: Record<string, Message>;
export default messages;

Message is the compiled form of one message: data, not a function. The declaration is the same for every locale and never changes, so commit it and tsc passes on a fresh clone before anything is compiled. The module is a .js file, so no compiler flag such as allowArbitraryExtensions is needed.

Why generic?

The declaration is a plain Record rather than one key per id, on purpose:

  • Ids are content hashes, stable but not meant to be written by hand.
  • Your code writes macros, and the transform inserts the id. Application code never references an id, so there is nothing to type.
  • A per-id type would change on every extraction, and every one of those changes would show up in a diff.

A custom id is just a readable key in the catalogue, and is looked up the same way.

Next

On this page