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

Vue3 Plugin import resolves to any in Nuxt 3 #2071

Closed
noook opened this issue Mar 14, 2023 · 7 comments · Fixed by #2147
Closed

Vue3 Plugin import resolves to any in Nuxt 3 #2071

noook opened this issue Mar 14, 2023 · 7 comments · Fixed by #2147
Labels
bug Something isn't working contribution welcome ⛰ pkg:nuxt Related to @pinia/nuxt typescript This issue is related to typings

Comments

@noook
Copy link

noook commented Mar 14, 2023

Reproduction

https://stackblitz.com/edit/nuxt-starter-4b7cfk?file=app.vue

Steps to reproduce the bug

Install pinia and @nuxt/pinia, run the dev server and let it generate the typings for the project.

Go to .nuxt/types/plugins.d.ts

See the following block:

type NuxtAppInjections = 
  // Here
  InjectionType<typeof import("../../node_modules/@pinia/nuxt/dist/runtime/plugin.vue3").default> &
  InjectionType<typeof import("../components.plugin").default> &
  InjectionType<typeof import("../../node_modules/nuxt/dist/head/runtime/lib/vueuse-head.plugin").default> &
  InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/router").default>

Visit the ../../node_modules/@pinia/nuxt/dist/runtime/plugin.vue3 file:

declare const _default: any;
export default _default;
// In a vue file
const app = useNuxtApp()
app.$pinia // any

Expected behavior

The property $pinia should be visible in the returned object of useNuxtApp()

// In a vue file
const app = useNuxtApp()
app.$pinia // Should be Pinia

Actual behavior

The vue 3 plugin type definitions are outputted as any

Additional information

No response

Copy link
Member

posva commented Mar 14, 2023

I'm not sure if this is a misusage of the Nuxt module in Pinia, a regression in Nuxt, or something else. Feel free to pick it up and propose a Pull Request!

@posva posva added bug Something isn't working typescript This issue is related to typings ⛰ pkg:nuxt Related to @pinia/nuxt contribution welcome labels Mar 14, 2023 — with Volta.net
@noook
Copy link
Author

noook commented Mar 14, 2023

I'm not very aware of how the modules work, but do you think it has something to do with the way the package is built ?
Given the output I gave in the initial message

declare const _default: any;
export default _default;

@danielroe
Copy link
Member

Yes, this seems like an issue with the module builder to me.

@posva
Copy link
Member

posva commented Mar 14, 2023

It needs to be updated here. I think it’s still using siroc

@danielroe
Copy link
Member

Happy to pick this up.

Copy link
Member

posva commented Mar 14, 2023

Feel free!

@dargmuesli
Copy link

Since anys are now unknowns in Nuxt 3.3, linting fails when accessing Nuxt app's $pinia: https://stackblitz.com/edit/github-acwmkj?file=app.vue (run npm run lint)

I see color-mode has runtime type definition, but pinia has not. Would it fix the issue if those types were added? Or is this issue different and creation of a separate issue would be good?

kyrel added a commit to voorhoede/tudelft-spacefinder that referenced this issue Mar 28, 2023
* fix casing for import
* convert parse-message to TypeScript
* explicit typing for injected Pinia until vuejs/pinia#2071 is fixed
* loading payload via fs, not dynamic import
* explicit non-null assertion
* typings for generateRoutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contribution welcome ⛰ pkg:nuxt Related to @pinia/nuxt typescript This issue is related to typings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants