Skip to content

Commit

Permalink
fix(index): check options.decorateReply is a boolean (#178)
Browse files Browse the repository at this point in the history
* fix(types/index): correct `decorateReply` type

Signed-off-by: Frazer Smith <frazer.dev@icloud.com>

* test(types/index): add tsd tests

* fix(index): check `options.decorateReply` is a boolean

---------

Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
  • Loading branch information
Fdawgs authored Dec 4, 2024
1 parent b2018a8 commit 0115450
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function fastifyAccepts (fastify, options, done) {
})
})

if (options.decorateReply) {
if (options.decorateReply === true) {
fastify.decorateReply('requestAccepts', replyAcceptMethod)

methodNames.forEach(methodName => {
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type FastifyAccepts = FastifyPluginCallback<fastifyAccepts.FastifyAcceptsOptions

declare namespace fastifyAccepts {
export interface FastifyAcceptsOptions {
decorateReply: boolean
decorateReply?: boolean | undefined
}

export const fastifyAccepts: FastifyAccepts
Expand Down
2 changes: 2 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import accepts from '..'
const app = fastify()

app.register(accepts)
app.register(accepts, { decorateReply: true })
app.register(accepts, { decorateReply: false })

app.get('/', (request, reply) => {
const accept = request.accepts()
Expand Down

0 comments on commit 0115450

Please sign in to comment.