Skip to content

Commit 1b2b8f1

Browse files
committed
Remove extra comments
1 parent b0831d2 commit 1b2b8f1

File tree

3 files changed

+44
-70
lines changed

3 files changed

+44
-70
lines changed

src/hooks/useDispatch.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@ import type { ReactReduxContextValue } from '../components/Context'
55
import { ReactReduxContext } from '../components/Context'
66
import { createStoreHook, useStore as useDefaultStore } from './useStore'
77

8-
export interface UseDispatch {
9-
<
10-
AppDispatch extends Dispatch<Action> = Dispatch<UnknownAction>
11-
>(): AppDispatch
12-
withTypes: <AppDispatch extends Dispatch<Action>>() => () => AppDispatch
8+
export interface UseDispatch<
9+
DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>
10+
> {
11+
<AppDispatch extends DispatchType = DispatchType>(): AppDispatch
12+
13+
withTypes: <
14+
OverrideDispatchType extends DispatchType
15+
>() => UseDispatch<OverrideDispatchType>
1316
}
14-
// export interface UseDispatch<
15-
// DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>
16-
// > {
17-
// <AppDispatch extends DispatchType = DispatchType>(): AppDispatch
18-
// withTypes: <
19-
// OverrideDispatchType extends DispatchType
20-
// >() => UseDispatch<OverrideDispatchType>
21-
// }
2217

2318
/**
2419
* Hook factory, which creates a `useDispatch` hook bound to a given context.
@@ -28,26 +23,22 @@ export interface UseDispatch {
2823
*/
2924
export function createDispatchHook<
3025
S = unknown,
31-
A extends Action<string> = UnknownAction
26+
A extends Action = UnknownAction
3227
// @ts-ignore
3328
>(context?: Context<ReactReduxContextValue<S, A> | null> = ReactReduxContext) {
3429
const useStore =
35-
// @ts-ignore
3630
context === ReactReduxContext ? useDefaultStore : createStoreHook(context)
3731

38-
const useDispatch = <
39-
AppDispatch extends Dispatch<A> = Dispatch<A>
40-
>(): AppDispatch => {
32+
const useDispatch = () => {
4133
const store = useStore()
42-
// @ts-ignore
4334
return store.dispatch
4435
}
4536

4637
Object.assign(useDispatch, {
4738
withTypes: () => useDispatch,
4839
})
4940

50-
return useDispatch as UseDispatch
41+
return useDispatch as UseDispatch<Dispatch<A>>
5142
}
5243

5344
/**

src/hooks/useSelector.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { React } from '../utils/react'
33

44
import type { ReactReduxContextValue } from '../components/Context'
55
import { ReactReduxContext } from '../components/Context'
6-
import type { EqualityFn, NoInfer, TypedUseSelectorHook } from '../types'
6+
import type { EqualityFn, NoInfer } from '../types'
77
import type { uSESWS } from '../utils/useSyncExternalStore'
88
import { notInitialized } from '../utils/useSyncExternalStore'
99
import {
@@ -66,26 +66,16 @@ export interface UseSelectorOptions<Selected = unknown> {
6666
devModeChecks?: Partial<DevModeChecks>
6767
}
6868

69-
export interface UseSelector {
70-
<TState = unknown, Selected = unknown>(
69+
export interface UseSelector<StateType = unknown> {
70+
<TState extends StateType = StateType, Selected = unknown>(
7171
selector: (state: TState) => Selected,
7272
equalityFnOrOptions?: EqualityFn<Selected> | UseSelectorOptions<Selected>
7373
): Selected
74-
withTypes: <TState>() => TypedUseSelectorHook<TState>
74+
75+
withTypes: <
76+
OverrideStateType extends StateType
77+
>() => UseSelector<OverrideStateType>
7578
}
76-
// export interface UseSelector<StateType = unknown> {
77-
// <TState extends StateType = StateType, Selected = unknown>(
78-
// selector: (state: TState) => Selected,
79-
// equalityFn?: EqualityFn<Selected>
80-
// ): Selected
81-
// <TState extends StateType = StateType, Selected = unknown>(
82-
// selector: (state: TState) => Selected,
83-
// options?: UseSelectorOptions<Selected>
84-
// ): Selected
85-
// withTypes: <
86-
// OverrideStateType extends StateType
87-
// >() => UseSelector<OverrideStateType>
88-
// }
8979

9080
let useSyncExternalStoreWithSelector = notInitialized as uSESWS
9181
export const initializeUseSelector = (fn: uSESWS) => {

src/hooks/useStore.ts

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context } from 'react'
2-
import type { Action as BasicAction, Store, UnknownAction } from 'redux'
2+
import type { Action, Store } from 'redux'
33
import type { ReactReduxContextValue } from '../components/Context'
44
import { ReactReduxContext } from '../components/Context'
55
import {
@@ -9,31 +9,25 @@ import {
99

1010
export 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
*/
4438
export 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

Comments
 (0)