Skip to content

Commit 632f078

Browse files
authored
Type safe improvements (#489)
* improvement: more type safe * WIP: build passing * WIP: composer type-safe implementation * more updates * updates * updates * export APIs * tweak types * add legacy API type safe * add createI18n and useI18n typesafe * tweak * tweak * more tweaks * updates * updates * update * update component injection APIs * add type-safe example * update processor for api-docs-gen * tweaks * update docs * tweak * more tweaks * update type-safe example
1 parent afedcf7 commit 632f078

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+5458
-1840
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dist
22
docs/api/*.md
33
!docs/api/injection.md
4-
types
4+
packages/vue-i18n/index.html
55
temp
66
coverage
77
node_modules

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"editor.codeActionsOnSave": {
1111
"source.fixAll.eslint": true
1212
},
13-
"typescript.tsdk": "node_modules/typescript/lib"
13+
"typescript.tsdk": "node_modules/typescript/lib",
14+
"volar.tsPlugin": true
1415
}

examples/lazy-loading/vite/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
"dev": "vite"
77
},
88
"dependencies": {
9-
"vue": "^3.0.7",
10-
"vue-i18n": "^9.0.0",
11-
"vue-router": "^4.0.5"
9+
"vue": "^3.0.11",
10+
"vue-i18n": "link:../../packages/vue-i18n",
11+
"vue-router": "^4.0.8"
1212
},
1313
"devDependencies": {
14-
"@intlify/vite-plugin-vue-i18n": "^2.0.2",
15-
"@vitejs/plugin-vue": "^1.1.5",
16-
"@vue/compiler-sfc": "^3.0.7",
17-
"vite": "^2.0.5"
14+
"@intlify/vite-plugin-vue-i18n": "^2.1.2",
15+
"@vitejs/plugin-vue": "^1.2.2",
16+
"@vue/compiler-sfc": "^3.0.11",
17+
"vite": "^2.3.0"
1818
},
1919
"private": true
2020
}

examples/lazy-loading/vite/src/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</div>
2828
</template>
2929

30-
<script>
30+
<script lang="ts">
3131
import { defineComponent, watch, ref } from 'vue'
3232
import { useRouter } from 'vue-router'
3333
import { useI18n } from 'vue-i18n'
@@ -50,7 +50,7 @@ export default defineComponent({
5050
5151
// sync to switch locale from router locale path
5252
watch(router.currentRoute, route => {
53-
currentLocale.value = route.params.locale
53+
currentLocale.value = route.params.locale as string
5454
})
5555
5656
/**
@@ -61,7 +61,7 @@ export default defineComponent({
6161
*/
6262
watch(currentLocale, val => {
6363
router.push({
64-
name: router.currentRoute.value.name,
64+
name: router.currentRoute.value.name!,
6565
params: { locale: val }
6666
})
6767
})

examples/lazy-loading/vite/src/i18n.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { I18n, I18nOptions, Composer } from 'vue-i18n'
66
export const SUPPORT_LOCALES = ['en', 'ja']
77

88
export function setupI18n(options: I18nOptions = { locale: 'en' }): I18n {
9-
const i18n = createI18n(options) as I18n
9+
const i18n = createI18n(options)
1010
setI18nLanguage(i18n, options.locale!)
1111
return i18n
1212
}
@@ -24,12 +24,12 @@ export function setI18nLanguage(i18n: I18n, locale: string): void {
2424
*
2525
* axios.defaults.headers.common['Accept-Language'] = locale
2626
*/
27-
document.querySelector('html').setAttribute('lang', locale)
27+
document.querySelector('html')!.setAttribute('lang', locale)
2828
}
2929

3030
export async function loadLocaleMessages(i18n: I18n, locale: string) {
3131
// load locale messages
32-
const messages = await import(/* @vite-ignore */ `./locales/${locale}.yaml`)
32+
const messages = await import(/* @vite-ignore */ `./locales/${locale}.json`)
3333

3434
// set locale and locale message
3535
i18n.global.setLocaleMessage(locale, messages.default)

0 commit comments

Comments
 (0)