Vetur: Global virtual methods and properties

Created on 28 Nov 2020  路  9Comments  路  Source: vuejs/vetur

Global virtual methods

How can i describe global virtual methods like $t for i18n? I didn't see insgructions in the documentation. You don't have the feature or I can't find solution?

I use only JsDoc and simple JS. Without typescript

image

Error: Property '$t' does not exist on type 'CombinedVueInstance<{ openedSubMenuId: any; } & { openSub(id: any): void; closeSub(): void; } & { nav: NavItem[]; value: boolean; } & Vue, object, object, object, Record>'

image

question

Most helpful comment

Yes. And it's explained in the docs also: https://i18n.nuxtjs.org/setup#typescript :)

(nuxt-i18n maintainer here ;))

All 9 comments

You fix this the same way as with any other package that provides types. You add the package name to the types array in tsconfig.json.

{
    "compilerOptions": {
        // ...
        "types": [
            "vue-i18n",
        ],
    },
}

You fix this the same way as with any other package that provides types. You add the package name to the types array in tsconfig.json.

{
    "compilerOptions": {
        // ...
        "types": [
            "vue-i18n",
        ],
    },
}

I forgot to say. I don't use typescript. I setup types by JsDoc
image

The same answer applies.

The same answer applies.

It doesn't work.

And I have to add empty ts file to avoid this error in tsconfig
image

Why would it be empty if I told you to add this to fix it: https://github.com/vuejs/vetur/issues/2502#issuecomment-735225830
?

Why would it be empty if I told you to add this to fix it: #2502 (comment)
?

You told me add tsconfig. I did it. Read my comment closely. "I have to add empty ts file to avoid this error in tsconfig" - wihout any ts file in the project I have the problem in the tsconfig

Well, you should also have the usual boilerplate. Not only the extra part that I've written before. For example something like:

{
    "compilerOptions": {
        "baseUrl": ".",
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "esModuleInterop": true,
        "allowJs": true,
        "checkJs": true,
        "allowSyntheticDefaultImports": true,
        "lib": ["dom", "esnext"],
        "noEmit": true,
        "resolveJsonModule": true,
        "strict": true,
        "types": [
            "vue-i18n",
        ],
    },
}

And if you have further problems then create a repro as we can't be guessing your problem from vague comments forever.

Well, you should also have the usual boilerplate. Not only the extra part that I've written before. For example something like:

{
    "compilerOptions": {
        "baseUrl": ".",
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "esModuleInterop": true,
        "allowJs": true,
        "checkJs": true,
        "allowSyntheticDefaultImports": true,
        "lib": ["dom", "esnext"],
        "noEmit": true,
        "resolveJsonModule": true,
        "strict": true,
        "types": [
            "vue-i18n",
        ],
    },
}

And if you have further problems then create a repro as we can't be guessing your problem from vague comments forever.

Thank you! It's my fault. I use nuxt and I need add this types

{
  "compilerOptions": {
    "types": ["@nuxt/types", "nuxt-i18n"]
  }
}

Yes. And it's explained in the docs also: https://i18n.nuxtjs.org/setup#typescript :)

(nuxt-i18n maintainer here ;))

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thibautguedou3 picture thibautguedou3  路  3Comments

gabrielboliveira picture gabrielboliveira  路  3Comments

shaunc picture shaunc  路  3Comments

muhajirdev picture muhajirdev  路  3Comments

LukeLin picture LukeLin  路  3Comments