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

fix(nuxt): usePinia composable type #2890

Merged
merged 6 commits into from
Feb 12, 2025
Merged

Conversation

th1m0
Copy link
Contributor

@th1m0 th1m0 commented Jan 18, 2025

This PR fixes a type issue in the nuxt module. using the composable usePinia would always return unknown while it should always return the Pinia type.

Before: composable.d.ts

export * from 'pinia';
export declare const usePinia: () => unknown;

After: composable.d.ts

import type { Pinia } from 'pinia';
export * from 'pinia';
export declare const usePinia: () => Pinia;

Copy link

netlify bot commented Jan 18, 2025

Deploy Preview for pinia-playground ready!

Name Link
🔨 Latest commit e8e4372
🔍 Latest deploy log https://app.netlify.com/sites/pinia-playground/deploys/67a076346eb69b0008380f19
😎 Deploy Preview https://deploy-preview-2890--pinia-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 18, 2025

Deploy Preview for pinia-official ready!

Name Link
🔨 Latest commit c670d5c
🔍 Latest deploy log https://app.netlify.com/sites/pinia-official/deploys/67ac63f12b7d360008791758
😎 Deploy Preview https://deploy-preview-2890--pinia-official.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@th1m0
Copy link
Contributor Author

th1m0 commented Feb 3, 2025

@posva would be lovely if this could be merged as I currently have to always use as Pinia after usePinia()

	const pinia = usePinia() as Pinia // `as Pinia` is required here because it's Unknown
    const profileStore = useProfileStore(pinia)

@th1m0 th1m0 changed the base branch from v2 to v3 February 11, 2025 22:22
@posva posva added the ⛰ pkg:nuxt Related to @pinia/nuxt label Feb 12, 2025
@posva
Copy link
Member

posva commented Feb 12, 2025

Does this happen in a blank project? It's the first time I see this issue

@th1m0
Copy link
Contributor Author

th1m0 commented Feb 12, 2025

Seems like it does, the type of the composable does not get into the build and defaults to unknown

https://stackblitz.com/edit/github-kd8twaqz?file=node_modules%2F%40pinia%2Fnuxt%2Fdist%2Fruntime%2Fcomposables.d.ts

@posva
Copy link
Member

posva commented Feb 12, 2025

It's so weird, this used to work so maybe a regression in Nuxt. I will merge but release later on after doing a pass on other Nuxt related PRs. Aiming for the end of the month. It's released. Note you can use getActivePinia(), it does the same thing, maybe I should just deprecate usePinia()

Copy link

pkg-pr-new bot commented Feb 12, 2025

Open in Stackblitz

npm i https://pkg.pr.new/@pinia/nuxt@2890
npm i https://pkg.pr.new/pinia@2890
npm i https://pkg.pr.new/@pinia/testing@2890

commit: c670d5c

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.23%. Comparing base (e3b5f6d) to head (c670d5c).
Report is 2 commits behind head on v3.

Files with missing lines Patch % Lines
packages/nuxt/src/runtime/composables.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##               v3    #2890   +/-   ##
=======================================
  Coverage   91.23%   91.23%           
=======================================
  Files          17       17           
  Lines        1381     1381           
  Branches      211      211           
=======================================
  Hits         1260     1260           
  Misses        120      120           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@posva posva merged commit a32fb3b into vuejs:v3 Feb 12, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⛰ pkg:nuxt Related to @pinia/nuxt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants