From: Eduardo San Martin Morote Date: Mon, 20 Jan 2020 17:44:50 +0000 (+0100) Subject: refactor: move types X-Git-Tag: 0.0.5~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eaf5869a65bf2807e8350663c4faf612c4b282dd;p=thirdparty%2Fvuejs%2Fpinia.git refactor: move types --- diff --git a/src/store.ts b/src/store.ts index 6db5db61..d33989cd 100644 --- a/src/store.ts +++ b/src/store.ts @@ -8,6 +8,8 @@ import { StoreWithGetters, StoreGetter, NonNullObject, + StoreAction, + StoreWithActions, } from './types' import { useStoreDevtools } from './devtools' @@ -41,17 +43,6 @@ export const setActiveReq = (req: NonNullObject | undefined) => export const getActiveReq = () => activeReq -export interface StoreAction { - (...args: any[]): any -} - -// in this type we forget about this because otherwise the type is recursive -type StoreWithActions> = { - [k in keyof A]: A[k] extends (this: infer This, ...args: infer P) => infer R - ? (this: This, ...args: P) => R - : never -} - // has the actions without the context (this) for typings export type Store< Id extends string, @@ -60,21 +51,6 @@ export type Store< A extends Record > = StoreWithState & StoreWithGetters & StoreWithActions -export type PiniaStore< - P extends Record> -> = P extends Record - ? { - [Id in P[name]['id']]: P[name] extends Store< - Id, - infer S, - infer G, - infer A - > - ? StoreWithGetters - : never - } - : never - /** * Creates a store instance * @param id unique identifier of the store, like a name. eg: main, cart, user diff --git a/src/types.ts b/src/types.ts index 55348e05..f2cbd8ce 100644 --- a/src/types.ts +++ b/src/types.ts @@ -56,7 +56,7 @@ export interface StoreWithState { state: S /** - * Private property defining the _req for this store + * Private property defining the request key for this store */ _r: NonNullObject @@ -80,6 +80,17 @@ export interface StoreWithState { subscribe(callback: SubscriptionCallback): () => void } +export interface StoreAction { + (...args: any[]): any +} + +// in this type we forget about this because otherwise the type is recursive +export type StoreWithActions> = { + [k in keyof A]: A[k] extends (this: infer This, ...args: infer P) => infer R + ? (this: This, ...args: P) => R + : never +} + export interface DevtoolHook { on( event: string,