Definitelytyped: Error: Interface 'Response<ResBody>' incorrectly extends interface 'Response'

Created on 9 Aug 2020  路  5Comments  路  Source: DefinitelyTyped/DefinitelyTyped

When I compile from typescript I get this bug

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 {
                     ~~~~~~~~

from my 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"
    }

Anyone know what's wrong?

Most helpful comment

I am pretty sure this is related to a recent update to @types/express-serve-static-core that changed the declaration of Response.locals from any to Record<string, any> .... this basically defines it as an object with potentially infinite properties and prevents constraining it to a more specific type. I think it should be reverted back to an any or add support for specifying the type of locals via a generic parameter.

All 5 comments

had the same error. you've probably defined/extended your own Response interface somewhere in your code.
change your definition to:

interface Response {
locals: Record<any, _your interface definition_>;
}

I'm getting this right now as well; I just double checked and I do not have "Response" anywhere in my codebase, so I definitely haven't tampered with it. I'm seeing this in VSCode on Windows.

I was able to fix this error. I first tried to re-create this as a minimal code needed to re-produce (in a sub folder in my main project) and everything worked fine, and then I started copying all my main files into that minimal example and it still worked. Pretty soon I had my whole project in that sub folder and it worked there. So then I just deleted my main code and moved the sub folder contents up a level and it still worked there...... Not sure what is the difference. I have a hunch it may be the ordering of dependencies listed in the package.json might of changed which made it work...

I'm still having this issue, wondering if there are any updates? Thanks!

I am pretty sure this is related to a recent update to @types/express-serve-static-core that changed the declaration of Response.locals from any to Record<string, any> .... this basically defines it as an object with potentially infinite properties and prevents constraining it to a more specific type. I think it should be reverted back to an any or add support for specifying the type of locals via a generic parameter.

Was this page helpful?
0 / 5 - 0 ratings