Payload typing lost when using setCookie before
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
3.27.1
Plugin version
5.5.0
Node.js version
16.13.1
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11 (21H2)
Description
When using a schema for my route, I get payload typing. But when I use setCookie
on my reply, the payload get the type unknown
.
Steps to Reproduce
type TSchemaResponse = {
message: string
};
// ...
fastifyInstance.post<Response: TSchemaResponse>(
"/hello",
(request, reply) => {
reply.send({message: 123}); // typescript error as message should be a string
}
);
// ...
type TSchemaResponse = {
message: string
};
// ...
fastifyInstance.post<Response: TSchemaResponse>(
"/hello",
(request, reply) => {
reply
.setCookie("hello", "there")
.send({message: 123}); // no error (there should be an error)
}
);
// ...
Expected Behavior
The payload should still be typed after calling setCookie (as setCookie should return “this” type)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Set-Cookie - HTTP - MDN Web Docs
Indicates that the cookie is sent to the server only when a request is made with the https: scheme (except on localhost), and...
Read more >Solved: Set-Cookie and Response Body not getting sent toge...
Goal: send three Set-Cookies header + response.content in response body. What I've tried: After some tests with AssignMessage, I realized that ...
Read more >Set-Cookie not working in browser but works with Postman
I have implemented CORS configurations in my backend and frontend and all the other API requests work. However the Set-Cookie flag is not ......
Read more >Axios ignoring set-cookie in cross-origin setup on Chrome ...
The bug. Axios 'with-credentials' does not seem to be abiding and setting the proper cookies under Chrome and Brave in NON-incognito mode.
Read more >Set Cookie in Mock Service - Forums - IBM Support
The related processing rules does some processing and identity validation, generates an LTPAToken2 cookie and sets it for return to the client, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@hugoattal > thank you for the minimal reproducible example.
Thanks to this I was able to spot the cause of this issue. I will submit a PR to resolve this issue in a moment 😃
@darkgl0w Here it is: https://github.com/hugoattal/fastify-cookie-typing-bug-repro
Just run
pnpm install
(should also work with npm) and you can see the error undersrc/handler.ts