反应路由器中的错误:"预期类型。TS1110' 删除我的node_modules文件夹和包锁.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的输出为Version 4.5.5node -v的输出为v16.13.0(如果有任何用处的话(。我想我可能破坏了与TS编译器有关的东西?我认为问题不在于react路由器库。。。

通过使用卸载和重新安装TS修复

npm uninstall typescript --save
npm install typescript --save-dev

如果您正在使用Visual Studio,并将前端和后端结合在一个解决方案中,则应检查软件包Microsoft的版本。TypeScript。MSBuild是最新的。

我已经通过在我的故事书项目中执行以下操作修复了错误

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

不确定这是否是正确的方法,但我通过删除node_modules/@types/react-router文件夹解决了这个问题。

最新更新