@nuxtjs/i18n - Vue: __VLS_ctx.$t is of type unknown
When I'm trying to use any translation such as
<p>{{ $t("common.ok") }}</p>
the $t is underlined with red and displays: Vue: __VLS_ctx.$t is of type unknown
as warning5 Replies
Hi @Dobby. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
This issue is related to type checking in Vue with Nuxt and i18n. The warning you're seeing suggests that the TypeScript compiler doesn't recognize the
$t
function, which is provided by the i18n plugin.
To resolve this, you can try the following approach:
1. Instead of using the global $t
in your template, you can import and use the useI18n
composable in your <script setup>
section. This should provide proper type inference:
This method is recommended in the Vue I18n documentation as seen here (https://stackoverflow.com/questions/77594888).
2. If you prefer to keep using $t
in your template, you might need to augment the global types for Vue. You can do this by creating a file named vue-i18n.d.ts
in your project's root or types
directory with the following content:
This should help TypeScript recognize $t
as a valid property on the Vue instance.
3. Make sure you have properly set up the i18n configuration in your nuxt.config.ts
file. It should include something like this:
And in your i18n.config.ts
:
These steps should help resolve the type checking issue for $t
in your Nuxt project with i18n. If you're still experiencing issues, you might want to check your Nuxt and i18n versions to ensure they are compatible and up to date.
Source for i18n configuration (https://stackoverflow.com/questions/77330239)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@209077102950088711> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
anyone with an idea?
if you have other modules installed try commenting them out one by one, I've had similar issues in the past (not with vue-i18n) that was caused by some unrelated module messing up with types.
@Dobby
@Morpheus
I see @Cake , i will try that solution
for now, i don’t use $t from plugins that nuxtjs/i18n provide, i use function t fron usei18n() @Dobby