diff --git a/types/index.d.ts b/types/index.d.ts index d90acd3ad..ff8ee840f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,7 +1,8 @@ -import './vue' -import { Locale, I18nOptions } from 'vue-i18n' +import VueI18n, { Locale, I18nOptions, IVueI18n } from 'vue-i18n' import { Context as NuxtContext } from '@nuxt/types' +import './vue' +// Deprecated export { NuxtVueI18n } from './nuxt-i18n' export { Locale } @@ -71,3 +72,17 @@ export interface Options extends BaseOptions { vueI18nLoader?: boolean vuex?: VuexOptions | false } + +export interface IVueI18nNuxt extends Required { + finalizePendingLocaleChange(): Promise + getBrowserLocale(): string | undefined + getLocaleCookie(): string | undefined + loadedLanguages: string[] | undefined + localeCodes: readonly Locale[] + localeProperties: LocaleObject + setLocale(locale: string): Promise + setLocaleCookie(locale: string): void + waitForPendingLocaleChange(): Promise +} + +export type NuxtI18nInstance = VueI18n & IVueI18n diff --git a/types/vue.d.ts b/types/vue.d.ts index 42dcca3f9..bf7b437ae 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -1,10 +1,10 @@ import 'vue' import 'vuex' +import 'vue-i18n' import '@nuxt/types' import { Location, RawLocation, Route } from 'vue-router' -import VueI18n, { IVueI18n } from 'vue-i18n' import { MetaInfo } from 'vue-meta' -import { BaseOptions, LocaleObject, Options } from '.' +import { Options, NuxtI18nInstance, IVueI18nNuxt } from '.' interface NuxtI18nComponentOptions { paths?: { @@ -29,22 +29,6 @@ interface NuxtI18nHeadOptions { type NuxtI18nMeta = Required> -declare module 'vue-i18n' { - // the VueI18n class expands here: https://goo.gl/Xtp9EG - // it is necessary for the $i18n property in Vue interface: "readonly $i18n: VueI18n & IVueI18n" - interface IVueI18n extends Required { - finalizePendingLocaleChange(): Promise - getBrowserLocale(): string | undefined - getLocaleCookie(): string | undefined - loadedLanguages: string[] | undefined - localeCodes: readonly Locale[] - localeProperties: LocaleObject - setLocale(locale: string): Promise - setLocaleCookie(locale: string): void - waitForPendingLocaleChange(): Promise - } -} - interface NuxtI18nApi { getRouteBaseName(route?: Route): string | undefined localePath(route: RawLocation, locale?: string): string @@ -53,6 +37,10 @@ interface NuxtI18nApi { switchLocalePath(locale: string): string } +declare module 'vue-i18n' { + interface IVueI18n extends IVueI18nNuxt {} +} + declare module 'vue/types/vue' { interface Vue extends NuxtI18nApi { // $i18n is already added by vue-i18n. @@ -70,11 +58,11 @@ declare module 'vue/types/options' { declare module '@nuxt/types' { interface Context extends NuxtI18nApi { - i18n: VueI18n & IVueI18n + i18n: NuxtI18nInstance } interface NuxtAppOptions extends NuxtI18nApi { - i18n: VueI18n & IVueI18n + i18n: NuxtI18nInstance } interface NuxtConfig { @@ -84,6 +72,6 @@ declare module '@nuxt/types' { declare module 'vuex/types/index' { interface Store extends NuxtI18nApi { - $i18n: VueI18n & IVueI18n + $i18n: NuxtI18nInstance } }