B
B
bormor2019-09-15 16:53:41
JavaScript
bormor, 2019-09-15 16:53:41

Vue i18n - "Property '$t' does not exist on type 'VueConstructor'" error. How can I fix it?

Using vue i18n in a typescript project.
How to use it correctly in .ts files?
This approach

// for i18n
import  Vue  from 'vue'
declare module 'vue/types/vue' {
  interface VueConstructor  {
    $t: any
  }
}
declare module 'vue/types/options' {
  interface ComponentOptions<V extends Vue> {
    t?: any
  }
}

(()=>{
  const test = Vue.$t('auth.title');
  console.log( test )
})()

Gives ts error
Property '$t' does not exist on type 'VueConstructor<Vue>"

How can this be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ihor Bratukh, 2019-09-15
@BRAGA96

$t must be on an instance of the Vue class, not a static property of it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question