-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Body object in request could be null (Type change) #3299
Conversation
I don't remember if we cover this use case in a not-ts test actually. Would you mind adding it? |
I think it will be a breaking change for most of the TypeScript users |
I don't think this is a bad thing. 2 situations:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for curiosity, the types accept req.body
as undefined, what's the use case to check the specific null condition?
When the users specify a Also, the default type is Example, // it is valid before and we know that body must be object
fastify.post<{ Body: object }>('/', { schema: { body: { type: 'object' } } }, function(request, reply) {
reply.send(request.body.error)
}) For |
Here the doubt: is it null or undefined?
|
The default value is Line 14 in fee3427
|
@fastify/core We know why are we using |
Thanks a lot, @jsumners! So, since #2731 was landed I'm -1 in this PR, since as @climba03003 mentioned, it may break some typescript users and in fact, in the next major release this behavior will change again. |
I'm -1 on this changes, in my code I mostly rely on request/reply schemas which should cover this case until I mark it explicitly as nullable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Could you share a snippet? Isn't this declaration fixing this issue? export const postWishlist = async (req: FastifyRequest<{ Body: foobar }>, resp: FastifyReply): Promise<void> => { If so, i think we should enforce people to use this kind of declaration as it's TypeScript compliant. And users should not use something like |
Sure, here's repository: https://github.com/L2jLiga/fastify-request-body-validation |
That's a blocker indeed. It shouldn't break the defined non null types like @L2jLiga shared. |
@ReeceXW do you want to finalize this PR? Reading the comments above I think we should:
is that correct @fastify/typescript ? |
Closed for no activity, feel free to reopen in case you still want to pursue this change |
Checklist
npm run test
andnpm run benchmark
and the Code of conduct