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
This is exactly what I want, but the issue here is for typing the query param in my req argument, the param I put GetArticleListRequestQueryParams is giving me an error in the router.ts:
No overload matches this call.
The last overload gave the following error.
Argument of type'(req: Request<unknown, unknown, unknown, GetArticleListRequestQueryParams, Record<string, any>>, res: Response<any, Record<string, any>>) => Promise<...>' is not assignable to parameter of type'RequestHandlerParams<ParamsDictionary, unknown, unknown, ParsedQs, Record<string, any>>'.
Type '(req: Request<unknown, unknown, unknown, GetArticleListRequestQueryParams, Record<string, any>>, res: Response<any, Record<string, any>>) => Promise<...>' is not assignable to type'RequestHandler<ParamsDictionary, unknown, unknown, ParsedQs, Record<string, any>>'.
Types of parameters 'req' and 'req' are incompatible.
Type 'Request<ParamsDictionary, unknown, unknown, ParsedQs, Record<string, any>>' is not assignable to type'Request<unknown, unknown, unknown, GetArticleListRequestQueryParams, Record<string, any>>'.
Types of property 'query' are incompatible.
Type 'ParsedQs' is missing the following properties from type'GetArticleListRequestQueryParams': page, pageSizets(2769)
index.d.ts(153, 5): The last overload is declared here.
By getting a look to Request.ReqQuery, I need to provide a ParsedQS type, which look like this:
So my question is, how can I give objects type to the query params for my filter attribute without making it throw an error ? (I tried putting just string, but then I get a never type on my if (parameters?.filter && typeof parameters.filter === "object" && "categories" in parameters.filter).
The only solution I found is to give the type on the const parameters with a as GetArticleListRequestQueryParams but it's not clean at all :/
thanks for the help 🔥
The text was updated successfully, but these errors were encountered:
Hello, I'm running into a problem typing filter query using the express router with my request controller
So basically, I want to be able to get custom filters in my request, like this: GET /article?page=1&pageSize=5&filter[categories]=categId
Using this request, using a console log on req.query, i get this:
//{ page: '1', pageSize: '5', filter: { categories: 'categId' } }
This is exactly what I want, but the issue here is for typing the query param in my req argument, the param I put GetArticleListRequestQueryParams is giving me an error in the router.ts:
By getting a look to Request.ReqQuery, I need to provide a ParsedQS type, which look like this:
So my question is, how can I give objects type to the query params for my filter attribute without making it throw an error ? (I tried putting just string, but then I get a never type on my
if (parameters?.filter && typeof parameters.filter === "object" && "categories" in parameters.filter)
.The only solution I found is to give the type on the
const parameters
witha as GetArticleListRequestQueryParams
but it's not clean at all :/thanks for the help 🔥
The text was updated successfully, but these errors were encountered: