Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't override route using ForestRequest in TypeScript #932

Open
mauricius opened this issue Apr 5, 2022 · 1 comment
Open

Can't override route using ForestRequest in TypeScript #932

mauricius opened this issue Apr 5, 2022 · 1 comment

Comments

@mauricius
Copy link

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
@AlessioFranceschi
Copy link

AlessioFranceschi commented Sep 12, 2024

For future reference to those who might find this issue, I had this issue too, the workaround was to cast inside the function.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants