forest-express-sequelize icon indicating copy to clipboard operation
forest-express-sequelize copied to clipboard

Can't override route using ForestRequest in TypeScript

Open mauricius opened this issue 2 years ago • 0 comments

Hello!

I'm trying to override a route by using the snippet provided here https://docs.forestadmin.com/woodshop/how-tos/translate-your-project-into-typescript/v8/migrate-sequelize-files#override-your-routes, however I can't get around some typing issues with ForestRequest that conflict with Express' Request.

This is my code:

router.post('/actions/close', permissionMiddlewareCreator.smartAction(), async (req: ForestRequest, res: Response) => {
    ...
});

Expected behavior

Compile successfully.

Actual behavior

Compilation error.

Failure Logs

No overload matches this call.
  The last overload gave the following error.
    Argument of type '(req: ForestRequest, res: Response) => Promise<void>' is not assignable to parameter of type 'RequestHandlerParams<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
      Type '(req: ForestRequest, res: Response) => Promise<void>' is not assignable to type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
        Types of parameters 'req' and 'req' are incompatible.
          Type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to type 'ForestRequest'.
            Types of property 'user' are incompatible.
              Type 'User | undefined' is not assignable to type 'User'.
                Type 'undefined' is not assignable to type 'User'.ts(2769)
[index.d.ts(163, 5): ]()The last overload is declared here.

Context

  • Package Version: "forest-express-sequelize": "^8.5.3"
  • Express Version: 4.17.1
  • Sequelize Version: 6.3.5
  • Database Dialect: mysql
  • Database Version: 5.7
  • TypeScript: 4.5.2

mauricius avatar Apr 05 '22 08:04 mauricius