ERROR in src/i18n.ts:30:3
TS2769: No overload matches this call.
Overload 1 of 2, '(options: I18nOptions<{ message: Record<string, LocaleMessageValue<VueMessageType>>; datetime: DateTimeFormat; number: NumberFormat; }, string, ComposerOptions<...> | VueI18nOptions<...>>, LegacyVueI18n?: any):
I18n<...>', gave the following error.
Type 'LocaleRecord<[string], VueMessageType>' is not assignable to type '{ [x: string]: Record<string, LocaleMessageValue<VueMessageType>>; }'.
Index signatures are incompatible.
Type 'VueMessageType' is not assignable to type 'Record<string, LocaleMessageValue<VueMessageType>>'.
Type 'string' is not assignable to type 'Record<string, LocaleMessageValue<VueMessageType>>'.
Overload 2 of 2, '(options: I18nOptions<{ message: Record<string, LocaleMessageValue<VueMessageType>>; datetime: DateTimeFormat; number: NumberFormat; }, { ...; }, ComposerOptions<...> | VueI18nOptions<...>>, LegacyVueI18n?: any): I18n<...>', gave the following error.
Property '"en-US"' is missing in type 'LocaleRecord<[string], VueMessageType>' but required in type '{ "en-US": Record<string, LocaleMessageValue<VueMessageType>>; }'.
28 | locale: process.env.VUE_APP_I18N_LOCALE || "en",
29 | fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || "en",
> 30 | messages: loadLocaleMessages(),
| ^^^^^^^^
31 | });
32 |
import { createI18n, LocaleMessages, VueMessageType } from "vue-i18n";
function loadLocaleMessages(): LocaleMessages<VueMessageType> {
const locales = require.context(
"./locales",
true,
/[A-Za-z0-9-_,\s]+\.json$/i
);
const messages: LocaleMessages<VueMessageType> = {};
locales.keys().forEach((key) => {
const matched = key.match(/([A-Za-z0-9-_]+)\./i);
if (matched && matched.length > 1) {
const locale = matched[1];
messages[locale] = locales(key).default;
}
});
return messages;
}
export default createI18n({
legacy: false,
locale: process.env.VUE_APP_I18N_LOCALE || "en",
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || "en",
messages: loadLocaleMessages(),
});