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

persist in defineStore gives typescript error (at least on Windows environment) #373

Open
5 tasks done
jrutila opened this issue Jan 23, 2025 · 0 comments
Open
5 tasks done
Labels
🔍️ pending triage This issue needs to be looked into

Comments

@jrutila
Copy link

jrutila commented Jan 23, 2025

Are you using Nuxt?

  • Check this box if you encountered the issue using Nuxt and the included module.

Describe the bug

Given following code:

import { defineStore } from 'pinia'

export const useTestStore = defineStore("testStore", {
  persist: true,
  state: () => ({
    test: 'test',
  }),
  actions: {
    setTest(uuu: number) {
      this.test = "help"
    }
  }
})

The persist: true gives following error when running npx vue-tsc:

stores/test.ts:4:3 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(id: "testStore", options: Omit<DefineStoreOptions<"testStore", { test: string; }, {}, { setTest(uuu: number): void; }>, "id">): StoreDefinition<"testStore", { ...; }, {}, { ...; }>', gave the following error.
    Object literal may only specify known properties, and 'persist' does not exist in type 'Omit<DefineStoreOptions<"testStore", { tesnever>, Pick<unknown, never>> | undefined): StoreDefinition<...>', gave the following error.
    Object literal may only specify known properties, and 'persist' does not exist in type '(helpers: SetupStoreHelpers) => unknown'. 

4   persist: true,
    ~~~~~~~

VS Code also highlights this problem. I set up a minimal reproduction environment and there the problem does not happen. Could this be a windows environment issue? Other is that the Stackblitz env is running Node v18.

You can run npx vue-tsc in the reproduction and see error about the this.test getting a number. On Windows env (with node v20) you also get the above error.

Reproduction

https://stackblitz.com/edit/nuxt-starter-5tjffbh4?file=stores%2Ftest.ts

System Info

------------------------------
- Operating System: Windows_NT
- Node Version:     v20.18.0
- Nuxt Version:     3.15.2
- CLI Version:      3.20.0
- Nitro Version:    2.10.4
- Package Manager:  [email protected]
- Builder:          -
- User Config:      compatibilityDate, devtools, modules
- Runtime Modules:  @pinia/[email protected], pinia-plugin-persistedstate/[email protected]
- Build Modules:    -
------------------------------

Used Package Manager

pnpm

Validations

@jrutila jrutila added the 🔍️ pending triage This issue needs to be looked into label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍️ pending triage This issue needs to be looked into
Projects
None yet
Development

No branches or pull requests

1 participant