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

Lack of context typing with useNuxtApp #539

Closed
thisismydesign opened this issue Sep 16, 2022 · 3 comments
Closed

Lack of context typing with useNuxtApp #539

thisismydesign opened this issue Sep 16, 2022 · 3 comments
Labels
bug Something isn't working types

Comments

@thisismydesign
Copy link

thisismydesign commented Sep 16, 2022

Environment

  • Operating System: Darwin
  • Node Version: v16.17.0
  • Nuxt Version: 2.16.0-27616340.013f051b
  • Nitro Version: 0.4.24
  • Package Manager: yarn@1.22.19
  • 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/axios@5.13.6, @nuxtjs/auth@4.9.1, @nuxtjs/apollo@4.0.1-rc.5, @nuxtjs/feed@2.0.0, @nuxtjs/sitemap@2.4.0, @nuxtjs/i18n@7.3.0, nuxt-rollbar-module@1.1.0
  • Build Modules: (), @nuxt/bridge@3.0.0-27700335.6dfc006

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 #130

Logs

No response

@antlionguard
Copy link

I think duplicate of this #465

@danielroe danielroe added bug Something isn't working types and removed pending triage labels Sep 23, 2022 — with Volta.net
@valh1996
Copy link

valh1996 commented Oct 5, 2022

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.)

@wattanx
Copy link
Collaborator

wattanx commented Apr 23, 2023

I believe this issue has been resolved at #130.
You can extend NuxtAppCompat to add types such as $auth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working types
Projects
None yet
Development

No branches or pull requests

5 participants