获取接口 'Response<ResBody>' 错误地扩展了接口 'Response'

ome*_*ega 5 node.js express typescript

我在 node.js 中使用 typescript 和 express,当我编译它时我得到当我从 typescript 编译时我得到这个错误

node_modules/@types/express-serve-static-core/index.d.ts:505:18 - error TS2430: Interface 'Response<ResBody>' incorrectly extends interface 'Response'.
  Types of property 'locals' are incompatible.
    Type 'Record<string, any>' is missing the following properties from type 'i18nAPI': locale, __, __n, __mf, and 5 more.

505 export interface Response<ResBody = any> extends http.ServerResponse, Express.Response {
                     ~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

来自我的 package.json

"dependencies": {
    "@types/i18n": "^0.8.6",
    "@types/jest": "^26.0.7",
    "@types/moment": "^2.13.0",
    "@types/node": "^14.0.26",
    "@types/node-schedule": "^1.3.0",
    "@types/ws": "^7.2.6",
    "@typescript-eslint/eslint-plugin": "^3.7.0",
    "@typescript-eslint/parser": "^3.7.0",
    "@types/express": "^4.17.7",
    "chokidar": "^3.4.1",
    "dblapi.js": "^2.4.0",
    "discord.js": "^12.2.0",
    "eslint": "^7.5.0",
    "eslint-plugin-jest": "^23.18.2",
    "express": "^4.17.1",
    "findit2": "^2.2.3",
    "i18n": "^0.10.0",
    "jest": "^26.1.0",
    "moment": "^2.27.0",
    "node-schedule": "^1.3.2",
    "npm-check-updates": "^7.0.3",
    "tree-kill": "^1.2.2",
    "ts-jest": "^26.1.4",
    "typescript": "^3.9.7"
}
Run Code Online (Sandbox Code Playgroud)

有谁知道怎么了?

fan*_*ard 18

尝试一下npm i -D @types/express-serve-static-core,启用skipLibCheck不是一个好主意。


小智 7

添加"skipLibCheck": truetsconfig.json。它对我有用。


ome*_*ega 0

我能够修复这个错误。我首先尝试将其重新创建为重新生成所需的最小代码(在我的主项目的子文件夹中),一切正常,然后我开始将所有主文件复制到该最小示例中,它仍然有效。很快我的整个项目就在那个子文件夹中,并且它在那里工作。所以然后我只是删除了我的主代码并将子文件夹内容上移了一个级别,它仍然在那里工作......不知道有什么区别。我有预感,package.json 中列出的依赖项的顺序可能会发生变化,从而使其工作......

参考: https: //github.com/DefinitelyTyped/DefinitelyTyped/issues/46639