StoreOnActionListenerContext,
SubscriptionCallback,
PiniaCustomProperties,
+ PiniaCustomStateProperties,
DefineStoreOptions,
} from './types'
export { MutationType } from './types'
Store,
GettersTree,
ActionsTree,
+ PiniaCustomStateProperties,
} from './types'
/**
*
* @param context - Context
*/
- (context: PiniaPluginContext): Partial<PiniaCustomProperties> | void
+ (context: PiniaPluginContext): Partial<
+ PiniaCustomProperties & PiniaCustomStateProperties
+ > | void
}
/**
* State of the Store. Setting it will replace the whole state.
*/
- $state: UnwrapRef<S>
+ $state: UnwrapRef<S> & PiniaCustomStateProperties<S>
/**
* Private property defining the pinia the store is attached to.
UnwrapRef<S> &
StoreWithGetters<G> &
StoreWithActions<A> &
- PiniaCustomProperties<Id, S, G, A>
+ PiniaCustomProperties<Id, S, G, A> &
+ PiniaCustomStateProperties<S>
/**
* Return type of `defineStore()`. Function that allows instantiating a store.
A /* extends ActionsTree */ = ActionsTree
> {}
+/**
+ * Properties that are added to every `store.$state` by `pinia.use()`
+ */
+export interface PiniaCustomStateProperties<S extends StateTree = StateTree> {}
+
/**
* Type of an object of Getters that infers the argument
*
*/
export type GettersTree<S extends StateTree> = Record<
string,
- ((state: UnwrapRef<S>) => any) | (() => any)
+ ((state: UnwrapRef<S & PiniaCustomStateProperties<S>>) => any) | (() => any)
>
/**
$actions: Array<keyof A>
}
+ export interface PiniaCustomStateProperties<S> {
+ myState: number
+ }
+
export interface DefineStoreOptions<Id, S, G, A> {
debounce?: {
// Record<keyof A, number>
expectType<string>(context.store.$id)
expectType<App>(context.app)
+ expectType<number>(context.store.$state.myState)
+ expectType<number>(context.store.myState)
+
return {
$actions: Object.keys(context.options.actions || {}),
}
const useStore = defineStore({
id: 'main',
+ state: () => ({}),
actions: {
one() {},
two() {
this.one()
+ expectType<number>(this.$state.myState)
+ expectType<number>(this.myState)
},
three() {
this.two()