简体   繁体   中英

Error in React-Router: 'Type expected. TS1110' after deleting my node_modules folder and package-lock.json

My project was working perfectly well but I went and accidentally deleted my node_modules folder and package-lock.json and then reinstalled everything using npm install and now I'm getting this error

Type expected.  TS1110

    149 |     failed: true;
    150 | };
  > 151 | declare type ParamParseSegment<Segment extends string> = Segment extends `${infer LeftSegment}/${infer RightSegment}` ? ParamParseSegment<LeftSegment> extends infer LeftResult ? ParamParseSegment<RightSegment> extends infer RightResult ? LeftResult extends string ? RightResult extends string ? LeftResult | RightResult : LeftResult : RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : ParamParseSegment<RightSegment> extends infer RightResult ? RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : Segment extends `:${infer Remaining}` ? Remaining : ParamParseFailed;

This is the tsconfig that is in my project. It's the same as it was before when it was working

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "noImplicitAny": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "downlevelIteration": true,
  },
  "include": [
    "src"
  ]
}

Output of tsc -v is Version 4.5.5 . Output of node -v is v16.13.0 if that is of any use. I'm thinking I might have broken something related to the TS compiler? I don't think the problem is with the react router library...

Fixed by uninstalling and reinstalling TS using

npm uninstall typescript --save

npm install typescript --save-dev

If you are using Visual Studio, and combine front-end with backend in one solution, you should check if the version of package Microsoft.TypeScript.MSBuild is up to date.

I have fixed the error by doing the following in my project with storybook

npm i react-router-dom@5.3.0
npm i @types/react-router-dom@5.3.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM