11import type { Context } from 'react'
2- import type { Action as BasicAction , Store , UnknownAction } from 'redux'
2+ import type { Action , Store } from 'redux'
33import type { ReactReduxContextValue } from '../components/Context'
44import { ReactReduxContext } from '../components/Context'
55import {
@@ -9,31 +9,25 @@ import {
99
1010export type StoreAction < StoreType extends Store > = StoreType extends Store <
1111 any ,
12- infer Action
12+ infer ActionType
1313>
14- ? Action
14+ ? ActionType
1515 : never
1616
17- export interface UseStore {
18- < State = any , Action extends BasicAction = UnknownAction > ( ) : Store <
19- State ,
20- Action
21- >
17+ export interface UseStore < StoreType extends Store > {
18+ ( ) : StoreType
2219
23- withTypes : < AppStore extends Store > ( ) => ( ) => AppStore
24- }
25- // export interface UseStore<StoreType extends Store = Store> {
26- // <
27- // State extends ReturnType<StoreType['getState']> = ReturnType<
28- // StoreType['getState']
29- // >,
30- // Action extends BasicAction = StoreAction<Store>
31- // >(): Store<State, Action>
20+ <
21+ StateType extends ReturnType < StoreType [ 'getState' ] > = ReturnType <
22+ StoreType [ 'getState' ]
23+ > ,
24+ ActionType extends Action = StoreAction < Store >
25+ > ( ) : Store < StateType , ActionType >
3226
33- // withTypes: <
34- // OverrideStoreType extends StoreType
35- // >() => UseStore<OverrideStoreType>
36- // }
27+ withTypes : <
28+ OverrideStoreType extends StoreType
29+ > ( ) => UseStore < OverrideStoreType >
30+ }
3731
3832/**
3933 * Hook factory, which creates a `useStore` hook bound to a given context.
@@ -42,31 +36,30 @@ export interface UseStore {
4236 * @returns {Function } A `useStore` hook bound to the specified context.
4337 */
4438export function createStoreHook <
45- S = unknown ,
46- A extends BasicAction = BasicAction
39+ StateType = unknown ,
40+ ActionType extends Action = Action
41+ > (
4742 // @ts -ignore
48- > ( context ?: Context < ReactReduxContextValue < S , A > | null > = ReactReduxContext ) {
43+ context ?: Context < ReactReduxContextValue <
44+ StateType ,
45+ ActionType
46+ > | null > = ReactReduxContext
47+ ) {
4948 const useReduxContext =
50- // @ts -ignore
5149 context === ReactReduxContext
5250 ? useDefaultReduxContext
5351 : // @ts -ignore
5452 createReduxContextHook ( context )
55- const useStore = <
56- State = S ,
57- Action2 extends BasicAction = A
58- // @ts -ignore
59- > ( ) => {
53+ const useStore = ( ) => {
6054 const { store } = useReduxContext ( )
61- // @ts -ignore
62- return store as Store < State , Action2 >
55+ return store
6356 }
6457
6558 Object . assign ( useStore , {
6659 withTypes : ( ) => useStore ,
6760 } )
6861
69- return useStore as UseStore
62+ return useStore as UseStore < Store < StateType , ActionType > >
7063}
7164
7265/**
0 commit comments