Skip to content

Commit

Permalink
fix(types): add PiniaCustomProperties to stores
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Mar 31, 2021
1 parent 40fcb24 commit a12d96d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions __tests__/storePlugins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('store plugins', () => {
const store = useStore(pinia)

expect(store.n).toBe(20)
// @ts-expect-error: n is a number
store.n.notExisting
})

it('can install plugins before installing pinia', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export {
createPinia,
Pinia,
PiniaStorePlugin,
PiniaCustomProperties,
} from './rootStore'
export { defineStore } from './store'
export { PiniaPlugin } from './plugin'
Expand All @@ -13,5 +12,8 @@ export {
StoreWithGetters,
StoreWithActions,
StoreWithState,
PiniaCustomProperties,
} from './types'

// TODO: remove in beta
export { createStore } from './deprecated'
13 changes: 6 additions & 7 deletions src/rootStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { InjectionKey, ref, Ref } from '@vue/composition-api'
import { StateTree, StoreWithState, StateDescriptor } from './types'
import {
StateTree,
StoreWithState,
StateDescriptor,
PiniaCustomProperties,
} from './types'
import { VueConstructor } from 'vue'
import type Vue from 'vue'

Expand All @@ -14,12 +19,6 @@ export const storesMap = new WeakMap<
Map<string, [StoreWithState<string, StateTree>, StateDescriptor<StateTree>]>
>()

/**
* Properties that are added to every store by `pinia.use()`
*/
// eslint-disable-next-line
export interface PiniaCustomProperties {}

export const piniaSymbol = (__DEV__
? Symbol('pinia')
: /* istanbul ignore next */
Expand Down
12 changes: 11 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export type Store<
S extends StateTree,
G,
A
> = StoreWithState<Id, S> & S & StoreWithGetters<G> & StoreWithActions<A>
> = StoreWithState<Id, S> &
S &
StoreWithGetters<G> &
StoreWithActions<A> &
PiniaCustomProperties

export type GenericStore = Store<
string,
Expand Down Expand Up @@ -138,3 +142,9 @@ declare global {
}
}
}

/**
* Properties that are added to every store by `pinia.use()`
*/
// eslint-disable-next-line
export interface PiniaCustomProperties {}

0 comments on commit a12d96d

Please sign in to comment.