@@ -7,23 +7,66 @@ import {
7
7
useReduxContext as useDefaultReduxContext ,
8
8
} from './useReduxContext'
9
9
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
16
20
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
+ */
17
29
export interface UseStore < StoreType extends Store > {
30
+ /**
31
+ * Returns the Redux store instance.
32
+ *
33
+ * @returns The Redux store instance.
34
+ */
18
35
( ) : StoreType
19
36
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
+ */
20
45
<
21
46
StateType extends ReturnType < StoreType [ 'getState' ] > = ReturnType <
22
47
StoreType [ 'getState' ]
23
48
> ,
24
- ActionType extends Action = StoreAction < Store >
49
+ ActionType extends Action = ExtractStoreActionType < Store >
25
50
> ( ) : Store < StateType , ActionType >
26
51
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
+ */
27
70
withTypes : <
28
71
OverrideStoreType extends StoreType
29
72
> ( ) => UseStore < OverrideStoreType >
0 commit comments