prazdevs/pinia-plugin-persistedstate

Typescript error when defining global options

Closed this issue · 4 comments

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

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

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

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');

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