Skip to content

Instantly share code, notes, and snippets.

@lil5
Last active November 16, 2020 08:05
Show Gist options
  • Save lil5/989a165f916ef155425ac24f8849a030 to your computer and use it in GitHub Desktop.
Save lil5/989a165f916ef155425ac24f8849a030 to your computer and use it in GitHub Desktop.
Force vue-i18n to function $t to return string
import VueI18n, {
Path, Values, Locale,
} from 'vue-i18n/types'
/**
* Overloads VueI18n interface to avoid needing to cast return value to string.
* @see https://github.com/kazupon/vue-i18n/issues/410
*/
declare module 'vue-i18n/types' {
export default class VueI18n {
t(key: Path, locale: Locale, values?: Values): string;
t(key: Path, values?: Values): string;
}
}
declare module 'vue/types/vue' {
interface Vue {
$t: typeof VueI18n.prototype.t;
}
interface VueConstructor<V extends Vue = Vue> {
i18n: typeof VueI18n.prototype;
}
}
export default VueI18n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment