![](/img/trans.png)
[英]Error: TypeScript error in /home/runner/work/avi/avi/node_modules/@types/react-router/index.d.ts(149,100): Type expected. TS1110
[英]Error in React-Router: 'Type expected. TS1110' after deleting my node_modules folder and package-lock.json
我的项目运行良好,但我不小心删除了我的 node_modules 文件夹和 package-lock.json,然后使用npm install
重新安装了所有内容,现在我收到此错误
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;
这是我项目中的 tsconfig。 和之前工作时一样
{
"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"
]
}
tsc -v
的 Output 是Version 4.5.5
。 node -v
的 Output 是v16.13.0
,如果它有用的话。 我在想我可能破坏了与 TS 编译器相关的东西? 我认为问题不在于反应路由器库......
通过使用卸载和重新安装 TS 修复
npm uninstall typescript --save
npm install typescript --save-dev
如果您使用的是 Visual Studio,并且在一个解决方案中结合了前端和后端,则应检查 package Microsoft.TypeScript.MSBuild 的版本是否是最新的。
我通过在我的项目中使用故事书执行以下操作来修复错误
npm i react-router-dom@5.3.0
npm i @types/react-router-dom@5.3.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.