Skip to content

fix: Fixes typing in Store when connecting #401

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

avil13
Copy link

@avil13 avil13 commented May 20, 2025

Description

When pinia-plugin-persistedstate is connected - stor types are broken.

The problem is that the type used is not imported.

This PR fixes this error.

image

@avil13 avil13 requested a review from prazdevs as a code owner May 20, 2025 08:15
@avil13
Copy link
Author

avil13 commented Jun 3, 2025

@prazdevs Hi. Do you have the ability to accept the PR?

@agross
Copy link

agross commented Jun 20, 2025

@prazdevs Please have a look, this is affecting our project as well.

@prazdevs
Copy link
Owner

That's rather odd because the type doesn't need to be imported as its used inside declare module 'pinia' which has Store.
Could you provide a repo where you reproduce the error ?

@avil13
Copy link
Author

avil13 commented Jun 29, 2025

@prazdevs

This error is reproduced on large projects, it looks like TS is failing.

Is there any reason why the Store dependency was removed from pinia imports?

@prazdevs
Copy link
Owner

It has never been added to my knowledge. We're redeclaring the module (pinia) so Typescript will look up for types in said module. If you add the import, TS tells you it's unused 🤔

@avil13
Copy link
Author

avil13 commented Jun 29, 2025

This is an ESLint warning, not TS

изображение

@prazdevs
Copy link
Owner

This is an ESLint warning, not TS

изображение

well there's also a ts warning above the eslint one 😅

@prazdevs
Copy link
Owner

prazdevs commented Jul 3, 2025

Closing this without a proper issue / reproduction repo where the error occurs 😥

@prazdevs prazdevs closed this Jul 3, 2025
agross added a commit to agross/pinia-repro that referenced this pull request Jul 7, 2025
@agross
Copy link

agross commented Jul 7, 2025

I only got around to trying to create a repro today. I started with our project's source code and removed code until there was no error running npm run type-check.

This is the repro: https://github.com/agross/pinia-repro

Please reopen here accordingly. To "fix" the error, run rm src/components/__tests__/ComponentUsingStore.spec.ts. I don't know why removing that file/test fixes the type errors. VS Code certainly doesn't show any for the auth.ts file, and npm run test:unit succeeds.

@avil13
Copy link
Author

avil13 commented Jul 10, 2025

@agross Thanks for the tip on how to look for the problem.

I have found what the cause is.

TS is trying to optimize AST. So it is not loading data that is not being used right now.

To load the extension type, you can do an import from a package that extends pinia.

@prazdevs reopen the current PR and I will add a fix.

@prazdevs prazdevs reopened this Jul 11, 2025
@avil13 avil13 force-pushed the fix/state-typing-error branch from 37a6f0d to d170382 Compare July 11, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants