When I build my react project I get an error like this.
export type ExtractRouteOptionalParam<T extends string, U = string | number | boolean> = T extends `${infer Param}?`
? { [k in Param]?: U }
: T extends `${infer Param}*`
? { [k in Param]?: U }
I am adding an answer for future reference for others.
Yes like others mentioned typescript was the issue.
I upgraded it to the latest version (currently 4.8.3). After upgrading, I had to fix a type issue on my redux saga file and I had to upgrade react-scripts to 4.0.1 to fix the Parsing error: Cannot read properties of undefined (reading 'map').
I updated typescript version to 4.1.6 and it worked for me. I tried newest version of typescript. It also works, but it doesn’t support all the features I need.
As Rohan Jayraj mentioned, it is better to upgrade typescript and react-scripts.
Second Option:
If you have ejected your application and have no other option then follow this
Delete lock files and node_modules in your repo
yarn.lock/ package-lock.json
node_modules
Run below commands to install and start your app
npm install –legacy-peer-deps
npm build [for prod]
npm start [for dev]
This is happening because dependency packages [react router in this case] using @types/react as a dependency with version * mentioned in their dependencies, rather than an optional peer dependency.
This issue will repeat for all the react typescript applications with new kind of types error everytime.
[error may be different everytime but this solution works]
5
Answers
I am adding an answer for future reference for others.
Yes like others mentioned typescript was the issue.
I upgraded it to the latest version (currently
4.8.3
). After upgrading, I had to fix a type issue on myredux saga
file and I had to upgradereact-scripts
to4.0.1
to fix theParsing error: Cannot read properties of undefined (reading 'map')
.I meet seem issue on yesterday. And I use typescript version is 3.9.3. I had try version 3.9.10 cannot sovle this problem
I updated typescript version to 4.1.6 and it worked for me. I tried newest version of typescript. It also works, but it doesn’t support all the features I need.
I’ve added
@types/react-router
with a version of5.1.14
as a dependency to my package.json file and installed it which solved the issue.First option:
As Rohan Jayraj mentioned, it is better to upgrade typescript and react-scripts.
Second Option:
If you have ejected your application and have no other option then follow this
Delete lock files and node_modules in your repo
yarn.lock/ package-lock.json
node_modules
Run below commands to install and start your app
This is happening because dependency packages [react router in this case] using @types/react as a dependency with version * mentioned in their dependencies, rather than an optional peer dependency.
This issue will repeat for all the react typescript applications with new kind of types error everytime.
[error may be different everytime but this solution works]