Skip to content

Commit

Permalink
Fix FastifyInstance::ready type definition (#802)
Browse files Browse the repository at this point in the history
* Fix FastifyInstance::ready type definition

* Add all FastifyInstance::ready() readyListener parameters possibilities definition

* Add FastifyInstance::ready() Promise usage ts defintion

* readyListener arg is not optional for callback usage of FastifyInstance::ready() ts definition

* Remove throw when callback is available on server ready types tests
  • Loading branch information
jeromemacias authored and mcollina committed Feb 26, 2018
1 parent d514d46 commit b4db20a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fastify.d.ts
Expand Up @@ -261,7 +261,10 @@ declare namespace fastify {
* Registers a listener function that is invoked when all the plugins have
* been loaded. It receives an error parameter if something went wrong.
*/
ready(readyListener?: () => void): void
ready(): Promise<FastifyInstance<HttpServer, HttpRequest, HttpResponse>>
ready(readyListener: (err: Error) => void): void
ready(readyListener: (err: Error, done: Function) => void): void
ready(readyListener: (err: Error, context: FastifyInstance<HttpServer, HttpRequest, HttpResponse>, done: Function) => void): void

/**
* Call this function to close the server instance and run the "onClose" callback
Expand Down
21 changes: 21 additions & 0 deletions test/types/index.ts
Expand Up @@ -251,3 +251,24 @@ server.setSchemaCompiler(function (schema: object) {
server.addSchema({})

server.printRoutes()

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

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

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

server.ready()
.then((context) => {
server.log.debug(context)
})
.catch((err) => {
server.log.error(err)
})

0 comments on commit b4db20a

Please sign in to comment.