Skip to content

Commit

Permalink
Add FastifyInstance::after typescript definition (#814)
Browse files Browse the repository at this point in the history
* Add FastifyInstance::after typescript definition

* Fix FastifyInstance::after typescript definition
  • Loading branch information
jeromemacias authored and mcollina committed Feb 28, 2018
1 parent 93fcef0 commit 9cc9f35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fastify.d.ts
Expand Up @@ -286,6 +286,14 @@ declare namespace fastify {
*/
register<T extends RegisterOptions<HttpServer, HttpRequest, HttpResponse>>(plugin: Plugin<HttpServer, HttpRequest, HttpResponse, T>, opts?: T): FastifyInstance<HttpServer, HttpRequest, HttpResponse>

/**
* `Register a callback that will be executed just after a register.
* It can take up to three parameters
*/
after(afterListener: (err: Error) => void): void
after(afterListener: (err: Error, done: Function) => void): void
after(afterListener: (err: Error, context: FastifyInstance<HttpServer, HttpRequest, HttpResponse>, done: Function) => void): void

/**
* Decorate this fastify instance with new properties. Throws an execption if
* you attempt to add the same decorator name twice
Expand Down
13 changes: 13 additions & 0 deletions test/types/index.ts
Expand Up @@ -272,3 +272,16 @@ server.ready()
.catch((err) => {
server.log.error(err)
})

server.after(function (err) {
if (err) throw err
})

server.after(function (err, done) {
done(err)
})

server.after(function (err, context, done) {
server.log.debug(context)
done(err)
})

0 comments on commit 9cc9f35

Please sign in to comment.