declare module '../src' {
export interface PiniaCustomProperties<Id> {
- n: number
+ pluginN: number
uid: App['_uid']
hasApp: boolean
idFromPlugin: Id
actions: {
incrementN() {
- return this.n++
+ return this.pluginN++
},
},
getters: {
- doubleN: (state) => state.n * 2,
+ doubleN: (state) => state.pluginN * 2,
},
})
// must call use after installing the plugin
pinia.use(({ app }) => {
- return { n: 20, uid: app._uid }
+ return { pluginN: 20, uid: app._uid }
})
const store = useStore(pinia)
- expect(store.n).toBe(20)
+ expect(store.pluginN).toBe(20)
expect(store.uid).toBeDefined()
- // @ts-expect-error: n is a number
- store.n.notExisting
+ // @ts-expect-error: pluginN is a number
+ store.pluginN.notExisting
// @ts-expect-error: it should always be 'test'
store.idFromPlugin == 'hello'
})
it('can install plugins before installing pinia', () => {
const pinia = createPinia()
- pinia.use(() => ({ n: 1 }))
+ pinia.use(() => ({ pluginN: 1 }))
pinia.use(({ app }) => ({ uid: app._uid }))
mount({ template: 'none' }, { global: { plugins: [pinia] } })
const store = useStore(pinia)
- expect(store.n).toBe(1)
+ expect(store.pluginN).toBe(1)
expect(store.uid).toBeDefined()
expect(store.hasApp).toBe(true)
})
// must call use after installing the plugin
pinia.use(() => {
- return { n: 20 }
+ return { pluginN: 20 }
})
mount({ template: 'none' }, { global: { plugins: [pinia] } })
// must call use after installing the plugin
pinia.use(() => {
- return { n: 20 }
+ return { pluginN: 20 }
})
mount({ template: 'none' }, { global: { plugins: [pinia] } })