Search code examples
javascripttypescriptexpresstypescript-typings

Property '' does not exist on type 'Request<ParamsDictionary>'


When trying to extend the Request interface from the package express to add some custom properties, I'm getting the following typescript error:

TS2339: Property '' does not exist on type 'Request<ParamsDictionary>'.

Do you know how to solve that?


Solution

  • Since a recent update of its typings and dependencies, I found that the following should fix the errors in your application.

    In your tsconfig.json

    {
      "compilerOptions": {
        //...
        "typeRoots": [
          "./custom_typings",
          "./node_modules/@types"
        ],
      }
    // ...
    }
    
    

    And in your custom typings

    // custom_typings/express/index.d.ts
    declare namespace Express {
        interface Request {
            customProperties: string[];
        }
    }