kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js

Home Page:https://kazupon.github.io/vue-i18n/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing `availableLocales` type in `I18nOptions` interface

hamidyfine opened this issue · comments

Reporting a bug?

When I try to use availableLocales in the new instance of the VueI18n get the following error:

    // Creating new instance
    i18n = new VueI18n({
        locale,
        availableLocales,
        fallbackLocale,
        messages,
        silentTranslationWarn: true,
        ...options
    });

Typescript error

Object literal may only specify known properties, and 'availableLocales' does not exist in type 'I18nOptions'.

I investigate the error in this file: /node_modules/vue-i18n/types/index.d.ts and find out that the type of availableLocales is missing from the I18nOptions interface.

Expected behavior

The availableLocales type gets recognized by typescript.

Reproduction

import Vue from 'vue';
import VueI18n from 'vue-i18n';

const i18n = new VueI18n({
    locale,
    availableLocales,
    fallbackLocale,
    messages,
    silentTranslationWarn: true
});

System Info

System:
    OS: Linux 5.13 Zorin OS 16.1
    CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
    Memory: 868.75 MB / 11.44 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.15.1 - /usr/bin/node
    Yarn: 1.22.18 - /usr/bin/yarn
    npm: 8.11.0 - /usr/bin/npm
  Browsers:
    Chrome: 103.0.5060.53
    Firefox: 101.0.1

Screenshot

No response

Additional context

No response

Validations

Thank you for your reproting!

availableLocales is read-only property on the VueI18n instance.
So, We couldn't pass the construction options of VueI18n

Type definition code is here:

vue-i18n/types/index.d.ts

Lines 138 to 160 in ac83e9b

interface I18nOptions {
locale?: Locale;
fallbackLocale?: FallbackLocale;
messages?: LocaleMessages;
dateTimeFormats?: DateTimeFormats;
numberFormats?: NumberFormats;
formatter?: Formatter;
modifiers?: Modifiers,
missing?: MissingHandler;
fallbackRoot?: boolean;
fallbackRootWithEmptyString?: boolean,
formatFallbackMessages?: boolean;
sync?: boolean;
silentTranslationWarn?: boolean | RegExp;
silentFallbackWarn?: boolean | RegExp;
preserveDirectiveContent?: boolean;
pluralizationRules?: PluralizationRulesMap;
warnHtmlInMessage?: WarnHtmlInMessageLevel;
sharedMessages?: LocaleMessages;
postTranslation?: PostTranslationHandler;
componentInstanceCreatedListener?: ComponentInstanceCreatedListener;
escapeParameterHtml?: boolean;
}

However, docs say availableLocales can be passed to the constructor option.
That is incorrect documentation
We need to fix it.

Thanks for your feedback!