mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 07:40:10 +00:00
fix(redux-actions): createAction<Payload>(actionType: string) and createAction(actionType: string) is incorrect. (#16643)
also see #15697
This commit is contained in:
6
types/redux-actions/index.d.ts
vendored
6
types/redux-actions/index.d.ts
vendored
@@ -58,6 +58,10 @@ export type ActionFunction3<T1, T2, T3, R> = (t1: T1, t2: T2, t3: T3) => R;
|
||||
export type ActionFunction4<T1, T2, T3, T4, R> = (t1: T1, t2: T2, t3: T3, t4: T4) => R;
|
||||
export type ActionFunctionAny<R> = (...args: any[]) => R;
|
||||
|
||||
export function createAction(
|
||||
actionType: string
|
||||
): ActionFunction0<Action<void>>;
|
||||
|
||||
export function createAction<Payload>(
|
||||
actionType: string,
|
||||
payloadCreator: ActionFunction0<Payload>
|
||||
@@ -85,7 +89,7 @@ export function createAction<Payload, Arg1, Arg2, Arg3, Arg4>(
|
||||
|
||||
export function createAction<Payload>(
|
||||
actionType: string
|
||||
): ActionFunctionAny<Action<Payload>>;
|
||||
): ActionFunction1<Payload, Action<Payload>>;
|
||||
|
||||
export function createAction<Payload, Meta>(
|
||||
actionType: string,
|
||||
|
||||
@@ -110,8 +110,11 @@ const typedActionHandlerWithReduceMap = ReduxActions.handleAction<TypedState, Ty
|
||||
|
||||
typedState = typedActionHandlerWithReduceMap({ value: 0 }, typedIncrementByActionWithMeta(10));
|
||||
|
||||
const act = ReduxActions.createAction<string>('ACTION1');
|
||||
act('hello').payload === 'hello';
|
||||
const act0 = ReduxActions.createAction('ACTION0');
|
||||
act0().payload === null;
|
||||
|
||||
const act1 = ReduxActions.createAction<string>('ACTION1');
|
||||
act1('hello').payload === 'hello';
|
||||
|
||||
const act2 = ReduxActions.createAction('ACTION2', (s: {load: boolean}) => s);
|
||||
act2({load: true}).payload.load === true;
|
||||
@@ -119,7 +122,7 @@ act2({load: true}).payload.load === true;
|
||||
const act3 = ReduxActions.createAction('ACTION3', (s: string) => ({s}));
|
||||
act3('hello').payload.s === 'hello';
|
||||
|
||||
ReduxActions.handleAction<{ hello: string }, string>(act, (state, action) => {
|
||||
ReduxActions.handleAction<{ hello: string }, string>(act1, (state, action) => {
|
||||
return { hello: action.payload };
|
||||
}, {hello: 'greetings'});
|
||||
|
||||
@@ -131,7 +134,7 @@ ReduxActions.handleAction(act3, (state, action) => {
|
||||
return { hello: action.payload.s };
|
||||
}, {hello: 'greetings'});
|
||||
|
||||
ReduxActions.handleAction(ReduxActions.combineActions(act, act3, act2), (state, action) => {}, 0);
|
||||
ReduxActions.handleAction(ReduxActions.combineActions(act1, act3, act2), (state, action) => {}, 0);
|
||||
|
||||
/* can't do this until it lands in 2.2, HKTs
|
||||
ReduxActions.handleAction(act, (state, action) => {
|
||||
|
||||
Reference in New Issue
Block a user