@redux-requests/react: ordinary event passed into dispatchRequest produces typescript error
See original GitHub issueActual behaviour
TypeScript throws type error when non-RequestAction instance is passed into dispatchRequest function.
Expected behaviour
TypeScript doesn’t throw types error when non-RequestAction is passed into dispatchRequest function
Bug description:
According to documentation dispatchRequest function is just a wrapper for native redux dispatch function, and used only to add proper type checks. From my point of view that should mean that his function should be able to accept RequestAction as well as any other ordinary redux action. And it does accepts, but because of wrong typescript typings for that function typescript fails with error if I try to pass any non-RequestAction instance to this function.
Code example
Live example _(this code will not work because react hook is used outside any react component, redux is not initialised etc. - I tried to make code as short as possible to focus only on main issue - typescript error)
In case of live example not works - there is the source code:
import { useDispatchRequest } from "@redux-requests/react";
import { RequestAction } from "@redux-requests/core";
// Request action creator:
export const createRequestAction = (): RequestAction => ({
type: "SOME_REQUEST_ACTION",
payload: {
request: {
url: "google.com"
}
}
});
// Normal action creator:
export const createNormalAction = () => ({
type: "SOME_NORMAL_ACTION",
payload: "any payload for normal action"
});
// eslint-disable-next-line
const dispatch = useDispatchRequest();
// Example #1 - pass any normal action produces typescript error:
dispatch(createNormalAction());
// Example #1 - pass RequestAction works fine:
dispatch(createRequestAction());
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top GitHub Comments
Thx, I will take a look! Also, if you have time, I would appreciate your opinions in issues labeled as
advice wanted
especially https://github.com/klis87/redux-requests/issues/432@john-wennstrom ok, good you found the problem, co closing then