Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Error: TypeScript error in /home/runner/work/avi/avi/node_modules/@types/react-router/index.d.ts(149,100): Type expected. TS1110

Ask Question

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 }

How to solve this?

Well there ya go, your TypeScript version is out of date and doesn't support template literal types. – kelsny Sep 14, 2022 at 16:07 @kelly Okay, but we didn't have any issues until today. What is the reason? and this is inside node modules – Rohan Jayaraj Sep 14, 2022 at 16:10 I'm not sure about that but you should just upgrade your TypeScript version to fix the problem. – kelsny Sep 14, 2022 at 16:10

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').

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

  • 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]

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.