@@ -7,23 +7,66 @@ import {
77 useReduxContext as useDefaultReduxContext ,
88} from './useReduxContext'
99
10- export type StoreAction < StoreType extends Store > = StoreType extends Store <
11- any ,
12- infer ActionType
13- >
14- ? ActionType
15- : never
10+ /**
11+ * Represents a type that extracts the action type from a given Redux store.
12+ *
13+ * @template StoreType - The specific type of the Redux store.
14+ *
15+ * @since 9.1.0
16+ * @internal
17+ */
18+ export type ExtractStoreActionType < StoreType extends Store > =
19+ StoreType extends Store < any , infer ActionType > ? ActionType : never
1620
21+ /**
22+ * Represents a custom hook that provides access to the Redux store.
23+ *
24+ * @template StoreType - The specific type of the Redux store that gets returned.
25+ *
26+ * @since 9.1.0
27+ * @public
28+ */
1729export interface UseStore < StoreType extends Store > {
30+ /**
31+ * Returns the Redux store instance.
32+ *
33+ * @returns The Redux store instance.
34+ */
1835 ( ) : StoreType
1936
37+ /**
38+ * Returns the Redux store instance with specific state and action types.
39+ *
40+ * @returns The Redux store with the specified state and action types.
41+ *
42+ * @template StateType - The specific type of the state used in the store.
43+ * @template ActionType - The specific type of the actions used in the store.
44+ */
2045 <
2146 StateType extends ReturnType < StoreType [ 'getState' ] > = ReturnType <
2247 StoreType [ 'getState' ]
2348 > ,
24- ActionType extends Action = StoreAction < Store >
49+ ActionType extends Action = ExtractStoreActionType < Store >
2550 > ( ) : Store < StateType , ActionType >
2651
52+ /**
53+ * Creates a "pre-typed" version of {@linkcode useStore useStore}
54+ * where the type of the Redux `store` is predefined.
55+ *
56+ * This allows you to set the `store` type once, eliminating the need to
57+ * specify it with every {@linkcode useStore useStore} call.
58+ *
59+ * @returns A pre-typed `useStore` with the store type already defined.
60+ *
61+ * @example
62+ * ```ts
63+ * export const useAppStore = useStore.withTypes<AppStore>()
64+ * ```
65+ *
66+ * @template OverrideStoreType - The specific type of the Redux store that gets returned.
67+ *
68+ * @since 9.1.0
69+ */
2770 withTypes : <
2871 OverrideStoreType extends StoreType
2972 > ( ) => UseStore < OverrideStoreType >
0 commit comments