原正常运行的TypeScript代码执行yarn install后出现类型错误求助
TypeScript+Express依赖重装后出现异常类型错误
原本本地和服务器均正常运行的TypeScript代码,在生产环境重启(重启时会执行yarn install重新安装依赖)后出现类型错误,本地执行yarn install后也复现了相同问题。
报错示例如下:
server/Startup.ts:119:12 - error TS2339: Property 'status' does not exist on type 'Response<any, Record<string, any>>'. 119 .status(HttpStatusCode.NOT_FOUND) ~~~~~~
server/routes/savings_report.routes.ts:17:17 - error TS2339: Property 'get' does not exist on type 'Router'. 17 this.router.get( ~~~
这些TypeScript错误不符合实际情况,Express Router确实存在get方法,Response对象也有status方法,且代码此前运行完全正常。目前不确定问题出在yarn、npm还是ts-node,已尝试以下方案:
- 使用npm安装依赖
- 清理npm和yarn缓存后重新安装
- 删除
yarn.lock和package-lock.json后重新安装 - 让同事克隆主分支上此前正常的代码运行,仍出现相同错误
内容的提问来源于stack exchange,提问作者Yared Terefe
相关产品推荐
相关产品推荐

