Skip to content
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

Type inference with the watch callback argument for locale. #630

Open
4 tasks done
kazupon opened this issue Aug 12, 2021 · 2 comments
Open
4 tasks done

Type inference with the watch callback argument for locale. #630

kazupon opened this issue Aug 12, 2021 · 2 comments
Labels
🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing typescript

Comments

@kazupon
Copy link
Member

kazupon commented Aug 12, 2021

Reporting a bug?

When locale is specified as the first argument of watch, the type inference of the watch callback argument cannot be inferred correctly.

image

Expected behavior

When locale is specified as the first argument of watch, the type inference of the watch callback argument should be inferred correctly.

locale type is WritableComputedRef<Locales>
https://github.com/intlify/vue-i18n-next/blob/master/packages/vue-i18n-core/src/composer.ts#L1131

so, watch callback argument type should be inferred with Locales.

Reproduction

https://github.com/intlify/vite-vue-i18n-starter/blame/repro-watch/src/App.vue#L26-L31

System Info

System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 390.03 MB / 64.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.17.0 - ~/bin/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.10 - ~/bin/.nvm/versions/node/v14.17.0/bin/yarn
    npm: 6.14.13 - ~/bin/.nvm/versions/node/v14.17.0/bin/npm
  Browsers:
    Chrome: 92.0.4515.131
    Safari: 14.1.2
  npmPackages:
    vue: ^3.2.1 => 3.2.1
    vue-i18n: ^9.2.0-beta.1 => 9.2.0-beta.1

Screenshot

No response

Additional context

Workaround:

watch((() => locale.value), newlocale => {
  console.log(typeof newLocale) // output is 'string'
})

image

watch(locale, newLocale => {
  const n = newLocale as unknown as string
})

Validations

@kazupon kazupon added Status: Review Needed Request for review comments Status: In Progress Work in Progress and removed Status: Review Needed Request for review comments labels Aug 12, 2021
@PeterAlfredLee
Copy link
Member

@kazupon

This might be a work around:

watch(() => locale.value, newLocale => {
  console.log(typeof newLocale)
})

I just tested, in this case, the type of newLocale is string.

@kazupon
Copy link
Member Author

kazupon commented Oct 22, 2021

@PeterAlfredLee
Oh... I forgot it use the function at watch 😅
Thanks!

So, I'll update the new workaround with your suggestion. 😉

@kazupon kazupon added 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing and removed Priority: Low Status: In Progress Work in Progress labels Nov 15, 2022 — with Volta.net
@kazupon kazupon added the typescript label Jan 11, 2023 — with Volta.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing typescript
Projects
None yet
Development

No branches or pull requests

2 participants