`i18n.global.locale` type definiton wrong
See original GitHub issueReporting a bug?
When I implemented a function to globally switch locale as follows:
The type definition for i18n.global.locale
is wrong:
By printing out the console, I was able to see that i18n.global.locale
should be a computed value
Expected behavior
TypeScript not throw error
Reproduction
Type definition problem
System Info
System:
OS: macOS 12.3.1
CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Memory: 171.65 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 8.6.0 - ~/.nvm/versions/node/v16.13.2/bin/npm
Watchman: 2021.10.18.00 - /usr/local/bin/watchman
Browsers:
Brave Browser: 91.1.26.77
Chrome: 101.0.4951.54
Safari: 15.4
"vue": "^3.2.25",
"vue-i18n": "^9.1.10",
"@intlify/vite-plugin-vue-i18n": "^3.4.0",
"@vitejs/plugin-vue": "^2.3.1",
Screenshot
No response
Additional context
No response
Validations
- Read the Contributing Guidelines
- Read the Documentation
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How would one use I18n in TS classes? #566
I've tried using the .global instance with. const i18n = createI18n({ legacy: false, locale: process.env.VUE_APP_I18N_LOCALE || 'en' ...
Read more >Internationalization for vue 3 vite with i18n
The i18n plugin registering using app.use(i18n) make a global function $t available for all the children components :
Read more >Composition API
You want to change the locale with setup , just get a global Composer with useI18n and change it using the locale property...
Read more >The Ultimate Vue Localization Guide
Dive into Vue localization and learn how to plug the Vue I18n library into your app, so you can make it accessible to...
Read more >Locale messages syntax | Vue I18n
// As Flowtype definition, Locale Messages syntax like BNF annotation type LocaleMessages = { [key: Locale]: LocaleMessageObject }; type ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
sorry, I’m focusing on nuxtjs/i18n for v8 alpha release. please
Type definitions in vue-i18n are really complex. I’m not a full-time OSS yet, so it may take some time until I’m starting on this issue.
To me it’s clear that this bug only occurs when
useScope: 'global'
inuseI18n
is specified. That is, withconst { locale } = useI18n()
I getconst locale: WritableComputedRef<string>
, while withconst { locale } = useI18n({ useScope: 'global' });
I getconst locale: WritableComputedRef<unknown>
.