-
Notifications
You must be signed in to change notification settings - Fork 42
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
DataOf not really working? #148
Comments
This is kind of the default behavior, since it looks like they haven't implement it with full functionality yet, defeating the a lot of purpose in the package, since validation it's crucially needed for POST requests, and using it with type inference. If you specified requestBody it also prevents you from reading/parsing it manually since the body was already used to construct the data object. That procedure it's documented here. But it's a contradiction, since if you define BodyRequest, it's not possbile to request.json() the body, it's already used and inside the data object. Also the the related type inference code is here: |
you can always declare it manually, but that defeats the purpose. export class ExampleRoute extends OpenAPIRoute {
static schema: OpenAPIRouteSchema = {
// more things
requestBody: MySchema
}
// in the handler:
async handle(
request: Request,
data: DataOf<typeof ExampleRoute.schema> & {
body: z.TypeOf<typeof MySchema>>
}
){/** doer */}
}
export const MySchema = z.object({
foo: fooSchema,
bar: barSchema
}) |
Hello, this part will get reworked on the next major release, i just didn't have enough time yet to get around to it |
I'm trying to use DataOf on a project, and TypeScript keeps resolving everything to
any
.For example, I have:
And then I do:
But the resolved types are always:
The text was updated successfully, but these errors were encountered: