Skip to content

Commit

Permalink
feat(plugins): allow void return
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Apr 27, 2021
1 parent 9db92ed commit 5ef7140
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/index.ts
Expand Up @@ -8,6 +8,9 @@ export { defineStore } from './store'
export {
StateTree,
Store,
GenericStore,
GenericStoreDefinition,
StoreDefinition,
StoreWithGetters,
StoreWithActions,
StoreWithState,
Expand Down
5 changes: 4 additions & 1 deletion src/rootStore.ts
Expand Up @@ -60,7 +60,10 @@ export const getClientApp = () => clientApp
* Plugin to extend every store
*/
export interface PiniaStorePlugin {
(context: { app: App; store: GenericStore }): Partial<PiniaCustomProperties>
(context: {
app: App
store: GenericStore
}): Partial<PiniaCustomProperties> | void
}

/**
Expand Down
26 changes: 26 additions & 0 deletions test-dts/plugins.test-d.ts
@@ -0,0 +1,26 @@
import {
defineStore,
expectType,
mapStores,
createPinia,
GenericStore,
} from '.'

const useCounter = defineStore({
id: 'counter',
state: () => ({ n: 0 }),
})

type CounterStore = ReturnType<typeof useCounter>

const computedStores = mapStores(useCounter)

expectType<{
counterStore: () => CounterStore
}>(computedStores)

const pinia = createPinia()

pinia.use(({ store }) => {
expectType<GenericStore>(store)
})

0 comments on commit 5ef7140

Please sign in to comment.