1

I am using create-react-app and its typescript template, but when trying to retrieve the type of the property 'pending' in 'GenericAsyncThunk' like in redux-toolkit docs like this:

type PendingAction = ReturnType<GenericAsyncThunk["pending"]>;

I get an error: Parsing error: Unexpected token, expected "]"

Edit: looks like the errors only shows up on my machine and works in CodeSandbox. The error appears when the project is ran with the command npm start. Here is the full output: enter image description here

Any suggestions on how to tackle this?

KestVir
  • 300
  • 3
  • 14

1 Answers1

0

Probably the actual parse error is a bit earlier in the file and the line it reports on is not the line with the error, but rather the line at which it has to give up, since it can't make any further sense of the file.

Try removing elements before this structure, or move this structure further up the page to see if you can prove the theory.

cefn
  • 2,895
  • 19
  • 28
  • I use the code which I now added to the question as a helper to setup reusable async request reducer. I tried removing the reducer, but the error still gets thrown when the app runs. – KestVir Apr 06 '21 at 21:44
  • Have to add another comment because I can not edit the previous one. Removing the the code where the reusable reducer is used gets rid of the error, but the server also has to be restarted, a simple refresh does not get rid of the error. – KestVir Apr 06 '21 at 22:18
  • But that code doesn't show the error, right? When you say 'I get an error' what command do you run to get the error, what tooling element prints out that error? We need more to go on. Also you are only 2 types away from having the full example within a CodeSandbox. Try clicking on Export > Open in CodeSandbox from your Typescript playground and finish the job? As long as "./@types/types"; is missing it won't fully work. CodeSandbox allows multiple files to be authored and imported, along with any npm module. If it works there, it's something wrong with your machine or config not the code. – cefn Apr 06 '21 at 22:18
  • Thank you for the suggestion. Will try to that whenever possible. – KestVir Apr 06 '21 at 22:51
  • Just tried to run the code in CodeSandbox and got no errors, however after downloading the code from the platform and running locally I got the same error as before. I updated the question accordingly. – KestVir Apr 07 '21 at 09:31
  • What command are you running that reports the error? Please include the command and it's output. – cefn Apr 07 '21 at 12:51
  • Thanks for taking the time. I updated the question with the command and the output – KestVir Apr 07 '21 at 13:13
  • Is your local typescript same version or different from sandbox? – Carmine Tambascia Feb 11 '22 at 10:54