Skip to content

Commit

Permalink
types: add type of this to the not found handler (#2102)
Browse files Browse the repository at this point in the history
* add type of `this` to the not found handler

* add test for previous commit
  • Loading branch information
chengluyu committed Feb 16, 2020
1 parent b44d859 commit 772cf5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fastify.d.ts
Expand Up @@ -688,7 +688,7 @@ declare namespace fastify {
/**
* Set the 404 handler
*/
setNotFoundHandler(handler: (request: FastifyRequest<HttpRequest>, reply: FastifyReply<HttpResponse>) => void): void
setNotFoundHandler(handler: (this: FastifyInstance<HttpServer, HttpRequest, HttpResponse>, request: FastifyRequest<HttpRequest>, reply: FastifyReply<HttpResponse>) => void): void

/**
* Set a function that will be called whenever an error happens
Expand Down
4 changes: 3 additions & 1 deletion test/types/index.ts
Expand Up @@ -505,7 +505,9 @@ server.get('/test-decorated-inputs', (req, reply) => {
(reply as DecoratedReply).utility()
})

server.setNotFoundHandler((req, reply) => {
server.setNotFoundHandler(function (req, reply) {
this.log.error('not found')
reply.code(404).send()
})

server.setErrorHandler((err, request, reply) => {
Expand Down

0 comments on commit 772cf5e

Please sign in to comment.