-
I am trying to adapt the library to match our API's response format, which is structured as follows: On success: {
"data": {} | [],
"meta": {}
} On error: {
"errors": [...],
"meta": {}
} The endpoints factory is currently configured like this: output: z.object({
data: z.object({
greetings: z.string(),
}),
meta: z.object({
test: z.string(),
}),
}), Questions
Current ApproachAt the moment, I’m manually adding types to the response to suppress TypeScript warnings, for example: response.json({
data: output.data as Record<string, never> | Record<string, never>[],
meta: output.meta as Record<string, never>,
}); Feedback and Suggestions
Any guidance or best practices would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @mima0815. Here is my recommendation to you.
Thus, you do the customizations you need and avoid assumptions. And each Endpoint would have a clear response schema: either object or array. In case for some reason you want to combine it into a single I hope it helps. |
Beta Was this translation helpful? Give feedback.
Hello @mima0815. Here is my recommendation to you.
ResultHandler
:express-zod-api/express-zod-api/src/result-handler.ts
Line 98 in 5f85ac0
express-zod-api/express-zod-api/src/result-handler.ts
Line 147 in 5f85ac0
a. Avoid using
as
in implementation, instead use type asserting conditions, like this:express-zod-api/express-zod-api/src/result-handler.ts
Line 182 in 5…