diff --git a/types/vuex-i18n/index.d.ts b/types/vuex-i18n/index.d.ts index e1f607ef39..f6b75afa1a 100644 --- a/types/vuex-i18n/index.d.ts +++ b/types/vuex-i18n/index.d.ts @@ -1,9 +1,10 @@ -// Type definitions for vuex-i18n 1.7 +// Type definitions for vuex-i18n 1.10 // Project: https://github.com/dkfbasel/vuex-i18n // Definitions by: Cedric Kemp // Noam Kfir +// Suleimanov Artem // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.9 import _Vue, { PluginObject } from "vue"; @@ -17,13 +18,21 @@ declare module "vue/types/vue" { } } +export interface i18nState { + fallback: string | null; + locale: string | null; + translations: { + [key: string]: Translations; + }; +} + export interface Translations { [key: string]: string | Translations; } export interface Ii18n { /** get the current locale */ - locale(): string; + locale(): string | null; /** get all the registered locales */ locales(): string[]; @@ -81,9 +90,14 @@ export interface Ii18n { localeExists(locale: string): boolean; /** - * check if the given key is available in the current or fallback locale + * check if the given key is available + * optional with a second parameter to limit the scope + * strict: only current locale (exact match) + * locale: current locale and parent language locale (i.e. en-us & en) + * fallback: current locale, parent language locale and fallback locale + * the default is fallback */ - keyExists(key: string): boolean; + keyExists(key: string, scope?: string): boolean; } declare const _default: { diff --git a/types/vuex-i18n/vuex-i18n-tests.ts b/types/vuex-i18n/vuex-i18n-tests.ts index 82d9d864d9..11010df30b 100644 --- a/types/vuex-i18n/vuex-i18n-tests.ts +++ b/types/vuex-i18n/vuex-i18n-tests.ts @@ -3,11 +3,16 @@ import Vue from "vue"; import { Store } from "vuex"; // load vuex i18n module -import vuexI18n from "vuex-i18n"; +import vuexI18n, { i18nState } from "vuex-i18n"; + +// declare interface for store's root state +interface RootState { + i18n: i18nState; +} // initialize the vuex store using the vuex module. note that you can change the -// name of the module if you wish -const store = new Store({}); +// name of the module if you wish +const store = new Store({}); // initialize the internationalization plugin on the vue instance. note that // the store must be passed to the plugin. the plugin will then generate some