-
Notifications
You must be signed in to change notification settings - Fork 964
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
fix(middleware): Update invoke middleware implementation #10537
Conversation
@dac09 I don't understand why you had to change to use an object here. Can you please try to explain in a bit more detail so even I can follow along 😄
It should be fine to pass invokeOptions even if they're not used. The receiving function can just ignore the parameter I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comments
Sure. In TS you cannot supply an required third parameter after a optional parameter (the middleware function). https://stackoverflow.com/questions/46958782/why-does-typescript-require-optional-parameters-after-required-parameters
Exactly. My original type was that invoke options was optional, which is incorrect. Invoke options are always supplied, even if the middleware is undefined. This happens when the middleware router doesn't find a match. The logic for whether to excecute the middleware sits inside the invoke function. |
Yeah, that much I knew. What I'm trying to say is that it's fine to leave both as optional. Having them optional just means that the Now the case may be that the third option is in all practical cases in fact passed to the function. But that doesn't change the fact that for the function itself the third parameter is still optional 🙂 |
Hmm you're right in that it CAN be optional, I was focusing on the auth ones and not the cases where you might register a middleware to handle POST requests (like an API endpoint). I'll close this for now, and come back if required. |
Found an issue while writing up the blogpost on middleware.
The invokeOptions is always supplied when invoking middleware, but may not always be used.
In order to do this, I had to change how middleware is invoked (use an object instead of parameters)