Skip to content

Commit

Permalink
fix: Update types (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliyaZelenko authored and paulgv committed Feb 9, 2019
1 parent 2ff6d84 commit 5f8f4d7
Showing 1 changed file with 89 additions and 3 deletions.
92 changes: 89 additions & 3 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,100 @@
import Vue from "vue";
import { RawLocation } from "vue-router";
import VueI18n from "vue-i18n";

/**
* Extends interfaces in Vue.js
* The nuxt-i18n types namespace
*/
declare namespace NuxtVueI18n {
type Locale = VueI18n.Locale

import Vue from "vue";
import { RawLocation } from "vue-router";
namespace Options {
// e.g.:
// [
// { code: 'en', iso: 'en-US', file: 'en.js' },
// { code: 'fr', iso: 'fr-FR', file: 'fr.js' },
// { code: 'es', iso: 'es-ES', file: 'es.js' }
// ]
interface LocaleObject {
code: Locale
// can be undefined: https://goo.gl/cCGKUV
iso?: string
// can be undefined: https://goo.gl/ryc5pF
file?: string
// Allow custom properties, e.g. "name": https://goo.gl/wrcb2G
[key: string]: any
}

interface DetectBrowserLanguageInterface {
useCookie: boolean
cookieKey: string
alwaysRedirect: boolean
fallbackLocale: Locale | null
}

interface Vuex {
moduleName: string
mutations: {
setLocale: string
setMessages: string
}
preserveState: boolean
}

// special options for a "app.i18n" property: https://goo.gl/UwNfZo
interface VueI18nInterface {
locales: Array<Locale | LocaleObject>
defaultLocale: null | Locale
differentDomains: boolean
forwardedHost: boolean
routesNameSeparator: string
beforeLanguageSwitch: () => any
onLanguageSwitched: () => any
}

// see options reference: https://github.com/nuxt-community/nuxt-i18n/blob/master/docs/options-reference.md
interface AllOptionsInterface extends VueI18nInterface {
vueI18n: VueI18n.I18nOptions
strategy: "prefix_except_default" | "prefix" | "prefix_and_default"
lazy: boolean
langDir: string | null
rootRedirect: string | null
detectBrowserLanguage: Options.DetectBrowserLanguageInterface
seo: false
baseUrl: string
vuex: Options.Vuex
parsePages: boolean
// see https://goo.gl/NbzX3f
pages: {
[key: string]: boolean | {
[key: string]: boolean | string
}
}
encodePaths: boolean
}
}
}

/**
* Extends types in vue
*/
declare module "vue/types/vue" {
interface Vue {
localePath(route: RawLocation, locale?: string): string;
switchLocalePath(locale: string): string;
getRouteBaseName(route: RawLocation): string;
// PHPStorm without this indicates that "$i18n" was not found.
readonly $i18n: VueI18n & IVueI18n;
}
}

/**
* Extends types in vue-i18n
*/
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 NuxtVueI18n.Options.VueI18nInterface {

}
}

0 comments on commit 5f8f4d7

Please sign in to comment.