bridge
bridge copied to clipboard
Lack of context typing with `useNuxtApp`
Environment
- Operating System:
Darwin
- Node Version:
v16.17.0
- Nuxt Version:
2.16.0-27616340.013f051b
- Nitro Version:
0.4.24
- Package Manager:
[email protected]
- Builder:
webpack
- User Config:
server
,head
,css
,env
,plugins
,components
,modules
,apollo
,feed
,build
,alias
,transpileDependencies
,i18n
,sitemap
,auth
,typescript
,serverHandlers
,devServerHandlers
,bridge
,buildModules
- Runtime Modules:
@nuxtjs/[email protected]
,@nuxtjs/[email protected]
,@nuxtjs/[email protected]
,@nuxtjs/[email protected]
,@nuxtjs/[email protected]
,@nuxtjs/[email protected]
,[email protected]
- Build Modules:
()
,@nuxt/[email protected]
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
I think duplicate of this #465
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.)
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
.