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
[zod-openapi] tsc
error TS2345 when using a query
input data
#200
Comments
Leveraging the schemas defined using `zod` we can infer the type of most of the input / output types for the API. There's a pending issue concerning the type inference of `query` parameters that is stuck to `never` currently (see honojs/middleware#200).
* Fix typing issues from `tsc` Leveraging the schemas defined using `zod` we can infer the type of most of the input / output types for the API. There's a pending issue concerning the type inference of `query` parameters that is stuck to `never` currently (see honojs/middleware#200). * Refactor env schema validation to use `zod` * Fix tests
Hi @Krow10, Apologies for the delayed response. We can only use the |
Hi @yusukebe, no worries thanks for the response. Not sure I follow, doesn't |
A bit late to respond ! Thank you for the example, looks like the proper way to parse it then. Maybe one last question then: in what context would you use The issue can probably be closed now, thanks again. |
Hi,
In the case of Zod OpenAPI or Zod Validator of Hono, there isn't a chance to use In Zod OpenAPI or Zod Validator, the input value of a query should be |
I have few experience with zod. I managed to do validate the string query param as a number and also parse it as a number this way:
That way, |
Hi team,
I encountered this issue when trying to build an API with more than one input type (e.g. PATH + QUERY like
/{path}?q=xxx
).When using
zod-openapi
with a route includingquery
input data with (or without)params
, the type resolution fails when trying to access the input from the handler.In this context (the sample file is provided at the end of this post)
the calls to
c.req.valid
will produce the following errors at compile time:that is the output of
bun run tsc --noEmit --pretty --skipLibCheck --strict src/min.ts
Note that the problem disappears if we just use the
param
as input:But not when commenting out the
param
and leaving just the query:Build traces
Looking at the build traces from
tsc
, we can see forparam
the display type is correct<T extends \"param\">(target: T) ...
allowing to proceed without any errors.Param only
However in the other cases, it resolves to
<T extends never>(target: T) ...
making it impossible to infer the type.Query only
Both
The full traces for each are available here: tsc.traces.tar.gz
Related
In #77, the problem appeared to be fixed by using
strict: true
for the config and upgrading to the latest versions ofhono
and@hono/zod-validator
. This doesn't seem to fix the problem in this case.System information
Bun version 1.0.2
Sample file
The text was updated successfully, but these errors were encountered: