]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor: move types
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 20 Jan 2020 17:44:50 +0000 (18:44 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 20 Jan 2020 18:21:46 +0000 (19:21 +0100)
src/store.ts
src/types.ts

index 6db5db61d60e5e1885d5a415d33f23db819a5111..d33989cda8942c076f2c99a9181a33932c63a186 100644 (file)
@@ -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<A extends Record<string, StoreAction>> = {
-  [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<string, StoreAction>
 > = StoreWithState<Id, S> & StoreWithGetters<S, G> & StoreWithActions<A>
 
-export type PiniaStore<
-  P extends Record<string, Store<any, any, any, any>>
-> = P extends Record<infer name, any>
-  ? {
-      [Id in P[name]['id']]: P[name] extends Store<
-        Id,
-        infer S,
-        infer G,
-        infer A
-      >
-        ? StoreWithGetters<S, G>
-        : never
-    }
-  : never
-
 /**
  * Creates a store instance
  * @param id unique identifier of the store, like a name. eg: main, cart, user
index 55348e0538a1eb36e07686283ea54d8a7ad2977f..f2cbd8ce95f194158a330431e88b653b172321d1 100644 (file)
@@ -56,7 +56,7 @@ export interface StoreWithState<Id extends string, S extends StateTree> {
   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<Id extends string, S extends StateTree> {
   subscribe(callback: SubscriptionCallback<S>): () => void
 }
 
+export interface StoreAction {
+  (...args: any[]): any
+}
+
+// in this type we forget about this because otherwise the type is recursive
+export type StoreWithActions<A extends Record<string, StoreAction>> = {
+  [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,