Skip to content

Commit

Permalink
Kill the bindActionCreators overload for now
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Dec 4, 2023
1 parent ece6c25 commit d4909d3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
32 changes: 17 additions & 15 deletions extend-redux.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Action, UnknownAction, ActionCreatorsMapObject } from 'redux'
import type { ThunkAction } from './src/index'

/**
Expand All @@ -15,26 +16,27 @@ declare module 'redux' {
* Overload for bindActionCreators redux function, returns expects responses
* from thunk actions
*/
function bindActionCreators<
ActionCreators extends ActionCreatorsMapObject<any>
>(
actionCreators: ActionCreators,
dispatch: Dispatch
): {
[ActionCreatorName in keyof ActionCreators]: ReturnType<
ActionCreators[ActionCreatorName]
> extends ThunkAction<any, any, any, any>
? (
...args: Parameters<ActionCreators[ActionCreatorName]>
) => ReturnType<ReturnType<ActionCreators[ActionCreatorName]>>
: ActionCreators[ActionCreatorName]
}
// TODO Fix this post-3.0.1
// export function bindActionCreators<
// ActionCreators extends ActionCreatorsMapObject<any>
// >(
// actionCreators: ActionCreators,
// dispatch: Dispatch
// ): {
// [ActionCreatorName in keyof ActionCreators]: ReturnType<
// ActionCreators[ActionCreatorName]
// > extends ThunkAction<any, any, any, any>
// ? (
// ...args: Parameters<ActionCreators[ActionCreatorName]>
// ) => ReturnType<ReturnType<ActionCreators[ActionCreatorName]>>
// : ActionCreators[ActionCreatorName]
// }

/*
* Overload to add thunk support to Redux's dispatch() function.
* Useful for react-redux or any other library which could use this type.
*/
export interface Dispatch<A extends Action = AnyAction> {
export interface Dispatch<A extends Action = UnknownAction> {
<ReturnType = any, State = any, ExtraThunkArg = any>(
thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, A>
): ReturnType
Expand Down
28 changes: 14 additions & 14 deletions typescript_test/typescript_extended/extended-redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ interface ActionDispatchs {
// also ensure standard action creators still work as expected.
// Unlike the main file, this declaration should compile okay because we've imported
// the global module override
const actions: ActionDispatchs = bindActionCreators(
{
anotherThunkAction,
promiseThunkAction,
standardAction
},
store.dispatch
)

const untypedStore = createStore(fakeReducer, applyMiddleware(thunk))

// Similarly, both of these declarations should pass okay as well
untypedStore.dispatch(anotherThunkAction())
untypedStore.dispatch(promiseThunkAction()).then(() => Promise.resolve())
// const actions: ActionDispatchs = bindActionCreators(
// {
// anotherThunkAction,
// promiseThunkAction,
// standardAction
// },
// store.dispatch
// )

// const untypedStore = createStore(fakeReducer, applyMiddleware(thunk))

// // Similarly, both of these declarations should pass okay as well
// untypedStore.dispatch(anotherThunkAction())
// untypedStore.dispatch(promiseThunkAction()).then(() => Promise.resolve())

0 comments on commit d4909d3

Please sign in to comment.