question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@redux-requests/react: ordinary event passed into dispatchRequest produces typescript error

See original GitHub issue

Actual 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:closed
  • Created 3 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
klis87commented, Jan 20, 2021

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

0reactions
klis87commented, Apr 21, 2021

@john-wennstrom ok, good you found the problem, co closing then

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - dispatchEvent Causes error failed to execute ...
Found a solution. For some TypeScript settings, new Event is type of 'Event' only when we insert the second parameter, as this example:...
Read more >
TypeScript doesn't allow event : CustomEvent in ... - GitHub
In my TypeScript project, I'm trying to write the following code: ... The problem is that the CustomEvent type gives me the error...
Read more >
TypeScript errors and how to fix them
Below you find a list of common TypeScript errors along with the buggy code and its fixed version. If you're interested in more...
Read more >
Exception Handling - TypeScript Deep Dive - Gitbook
Creates an instance representing an error that occurs when a numeric variable or parameter is outside of its valid range.
Read more >
Improving TypeScript error handling with exhaustive type ...
Discover an improved method for handling errors in TypeScript that solves problems that arise from returning null and throwing try...catch.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found