prazdevs / pinia-plugin-persistedstate

💾 Configurable persistence and rehydration of Pinia stores.
https://prazdevs.github.io/pinia-plugin-persistedstate/
MIT License
2.13k stars 121 forks source link

Typescript error when defining global options #306

Closed Agusdeluca96 closed 5 months ago

Agusdeluca96 commented 5 months ago

Describe the bug

When trying to set global configuration options via piniaPluginPersistedstate, the next typescript error get shown:

Screenshot 2024-06-04 at 17 28 57

Reproduction

https://stackblitz.com/edit/pinia-plugin-persistedstate-ts-error-global-options

System Info

System:
    OS: macOS 14.2.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 64.17 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 19.8.1 - ~/.nvm/versions/node/v19.8.1/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v19.8.1/bin/npm
    pnpm: 8.14.1 - /opt/homebrew/bin/pnpm
  Browsers:
    Brave Browser: 125.1.66.113
    Safari: 17.2.1

Used Package Manager

pnpm

Validations

prazdevs commented 5 months ago

Please provide a proper reproduction (repo/stackblitz) so I can investigate

Agusdeluca96 commented 5 months ago

Here is a stackblitz with reproduction (also editing original message to add it): https://stackblitz.com/edit/pinia-plugin-persistedstate-ts-error-global-options

prazdevs commented 5 months ago

If you want to pass global options, you must use the plugin factory as such

import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { createPersistedState } from 'pinia-plugin-persistedstate';
import './style.css';
import App from './App.vue';

const app = createApp(App);

const pinia = createPinia();
pinia.use(
  createPersistedState({
    key: (id) => `__skeleton__${id}`,
  })
);

app.use(pinia);
app.mount('#app');
Agusdeluca96 commented 5 months ago

My bad, it was pretty clear on de doc! Thank you Sacha!