bridge icon indicating copy to clipboard operation
bridge copied to clipboard

Lack of context typing with `useNuxtApp`

Open thisismydesign opened this issue 2 years ago • 2 comments

Environment

Reproduction

const { $auth } = useNuxtApp() gives any type, whereas nuxt2Context.$auth from const { nuxt2Context } = useNuxtApp() is typed correctly.

Describe the bug

Lack of typing

Additional context

Perhaps related to https://github.com/nuxt/bridge/issues/130

Logs

No response

thisismydesign avatar Sep 16 '22 12:09 thisismydesign

I think duplicate of this #465

antlionguard avatar Sep 16 '22 19:09 antlionguard

Same problem for me, as a workaround, I use :

const { nuxt2Context: { $repository, $toast, $i18n } } = useNuxtApp()

/!\ EDIT: Do not use this workaround if you plan to migrate to Nuxt3 : From doc: https://v3.nuxtjs.org/bridge/bridge-composition-api/#usecontext-and-withcontext useNuxtApp() also provides a key called nuxt2Context which contains all the same properties you would normally access from Nuxt 2 context, but it's advised not to use this directly, as it won't exist in Nuxt 3. Instead, see if there is another way to access what you need. (If not, please raise a feature request or discussion.)

valh1996 avatar Oct 05 '22 15:10 valh1996

I believe this issue has been resolved at https://github.com/nuxt/bridge/issues/130. You can extend NuxtAppCompat to add types such as $auth.

wattanx avatar Apr 23 '23 06:04 wattanx