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

RegisterRoute only accepts 2-5 arguments #79

Closed
jtanadi opened this issue Apr 6, 2020 · 3 comments
Closed

RegisterRoute only accepts 2-5 arguments #79

jtanadi opened this issue Apr 6, 2020 · 3 comments

Comments

@jtanadi
Copy link

jtanadi commented Apr 6, 2020

I'm working on migrating a service from express. One of the routes currently has 4 middlewares and the TS compiler is giving me an error: Expected 2-5 arguments, but got 6.

app.post("/api/upload", checkType, processFile, uploadFile, cleanup, handler)

After some digging, I think I found the source of the issue in the type declaration file. It seems odd to me that one could only place up to three middlewares before the handler, and after that would have to switch to a different pattern and use an array for the middlewares, placed after the handler. (Also, side note, the second block seems like a duplicate of the first one?)

interface RegisterRoute<P extends Protocol> {
    (
      path: string,
      handler: RequestHandler<P>,
      middlewares?: RequestHandler<P>[]
    ): Service<P>

// this seems like a duplicate?
    (
      path: string,
      handler: RequestHandler<P>,
      middlewares?: RequestHandler<P>[]
    ): Service<P>

    (
      path: string,
      middleware1: RequestHandler<P>,
      handler: RequestHandler<P>,
    ): Service<P>

    (
      path: string,
      middleware1: RequestHandler<P>,
      middleware2: RequestHandler<P>,
      handler: RequestHandler<P>,
    ): Service<P>

    (
      path: string,
      middleware1: RequestHandler<P>,
      middleware2: RequestHandler<P>,
      middleware3: RequestHandler<P>,
      handler: RequestHandler<P>,
    ): Service<P>
  }

Is it not possible to use a rest parameter, since all middlewares and handlers are RequestHandler<P>?

interface RegisterRoute<P extends Protocol> {
    (
      path: string,
      ...middlewaresAndHandler: RequestHandler<P>[]
    ): Service<P>
}
@jkyberneees
Copy link
Collaborator

Hi @jtanadi thanks for using restana and contributing to make it better.
Totally valid suggestions. I will update and release ASAP.

Regards

@jkyberneees
Copy link
Collaborator

Hi @jtanadi as promised, the fix is now available in v.4.3.1

Thanks

@jtanadi
Copy link
Author

jtanadi commented Apr 7, 2020

@jkyberneees Thanks much—that was quick!

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