-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling tm(key) emits error "TS2589: Type instantiation is excessively deep and possibly infinite." #1119
Calling tm(key) emits error "TS2589: Type instantiation is excessively deep and possibly infinite." #1119
Comments
same error when trying to use i18n in plain js(outside component) with |
Same here |
This has a Need More Info tag - anything in particular you are looking for?
error. |
Upgrading from |
我也遇到了相同的问题,降级后,解决了,十分感谢 |
Encountering the same issue with
I have noticed the type returning from the
The reason I need to use the |
For me the 2 versions throw same error |
Same issue - // i18n.ts
import { createI18n } from 'vue-i18n'
// Import locales
const messages = Object.fromEntries(
Object.entries(
import.meta.glob<{ default: any }>('../locales/*.y(a)?ml', { eager: true }))
.map(([key, value]) => {
const yaml = key.endsWith('.yaml')
return [
key.slice(key.lastIndexOf('/') + 1, yaml ? -5 : -4),
value.default,
]
}),
)
const i18n = createI18n({
legacy: false,
locale: 'en',
messages,
})
export const { t } = i18n.global
export default i18n Usage of // some.ts
import { t } from '../i18n'
const text = t('example')
// ^ - Type instantiation is excessively deep and possibly infinite. ts(2589) Error: If i import message entries one by one and set createI18n according to the docs I am not getting this error, so i guess the problem is messages being imported dynamically and incorrectly setting the generic for the createI18n. const en = import.meta.glob<{ default: any }>('../locales/en.yml', { eager: true })
type MessageSchema = typeof en
const messages = { en }
const i18n = createI18n<{ message: MessageSchema }, 'en'>({
legacy: false,
locale: 'en',
messages,
}) Is there a way I can make it work with dynamically imported messages? |
Hello! I was the same type issue and I've solved casting the messages files to import type { I18nOptions } from 'vue-i18n';
import { createI18n } from 'vue-i18n';
const messages = Object.fromEntries(
Object.entries(import.meta.glob<{ default: unknown }>(`./locales/*.json`, { eager: true })).map(([key, value]) => [
key.slice(10, -5),
value.default,
])
) as I18nOptions['messages'];
const i18n = createI18n({
locale: 'en',
messages,
});
export default i18n; I hope it helps you! |
I'm still experiencing this issue with v9.9.1, using |
Reporting a bug?
With Typescript v4.7, the call to tm(key) in the composition API sometimes results in a type error being thrown:
I can't seem to reproduce it consistently, so my only way of dealing with this for the moment is by sprinkling
@ts-ignore
's through my codebase.Expected behavior
Correct type processing of the Vue I18n composition API.
Reproduction
System Info
Screenshot
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: