-
-
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
fix(types): reply.getHeader can return numbers and arrays #4154
Conversation
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
I am sorry, that I make this remark now: I can understand if getHeader can return an array of strings. But numbers would mean, that we actually convert strings to numbers when we parse the headers. And I kind of doubt, that we actually do this in the header parser. |
@@ -38,7 +38,7 @@ export interface FastifyReply< | |||
send(payload?: ReplyType): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | |||
header(key: string, value: any): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | |||
headers(values: {[key: string]: any}): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | |||
getHeader(key: string): string | undefined; |
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.
Hi @Uzlopak,
Correct, this is more for the case where somewhere in the lifecycle a header is set via I was originally going to only add Hi @xtx1130 hopefully this also answers your query regarding using |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Currently, the type definition for
FastifyReply.getHeader
has a return type ofstring | undefined
. For a header that's allowed to appear multiple times (such asServer-Timing
), one might do something like:for which a call to
reply.getHeader('server-timing')
would return:Given this, and the type definition for Node's
getHeader
, I think the the type definition forFastifyReply.getHeader
should be updated to be:number | string | string[] | undefined
.Checklist
npm run test
andnpm run benchmark
and the Code of conduct