Function: generateMessageTypes()
generateMessageTypes(
catalogs,defaultLocale,moduleName?):string
Generate the TypeScript declaration of the default language's message keys and their arguments (the I18nMessages augmentation), as lakutata i18n types does. Each argument is typed by its use: number | bigint for {n, number}, number for a plural, string for a select, Date | number | string for a date or a time, any scalar for a plain argument; a currency argument without its currency adds an optional currency. The validation.* messages are left out.
Parameters
catalogs
The messages, as loadCatalogs gives them.
defaultLocale
string
The default language tag, whose messages are declared.
moduleName?
string
The module the application imports the i18n from, which the declaration augments: 'lakutata/com/i18n' by default, '@lakutata/i18n' for the applications importing the package directly.
Returns
string
The source of a .d.ts file.
Throws
When the default language has no messages.
Throws
When a message of the default language is not valid ICU MessageFormat.
Example
import {writeFile} from 'node:fs/promises'
import {generateMessageTypes, loadCatalogs} from 'lakutata/com/i18n'
await writeFile('src/i18n.d.ts', generateMessageTypes(await loadCatalogs(['./locales']), 'en'))