You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I noticed that if I use the Param() decorator to access a url param in a handler, it adds the url param to req.params. This field is not a part of the NextApiRequest interface, so I am unable to access the field in my middleware without typescript throwing errors about the field not existing.
I am aware that I can also access the url params as one big array under req.query.params, however that field is not set on the req object when I am mocking requests for tests. The params are only present under req.params.
I tried extending NextApiRequest into a new type that includes an optional params field, however createMiddlewareDecorator() is very explicit about only wanting the req argument to be of type NextApiRequest and nothing else, so that doesn't work.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
So I noticed that if I use the
Param()
decorator to access a url param in a handler, it adds the url param toreq.params
. This field is not a part of theNextApiRequest
interface, so I am unable to access the field in my middleware without typescript throwing errors about the field not existing.I am aware that I can also access the url params as one big array under
req.query.params
, however that field is not set on the req object when I am mocking requests for tests. The params are only present underreq.params
.I tried extending
NextApiRequest
into a new type that includes an optionalparams
field, howevercreateMiddlewareDecorator()
is very explicit about only wanting thereq
argument to be of typeNextApiRequest
and nothing else, so that doesn't work.Any thoughts on what to do here?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions