From 0da69d72580a9072a6e8ef1777742727151cebb4 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 15 Sep 2021 16:49:36 +0200 Subject: [PATCH 1/4] Fix validate() return type --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 0bc2d90..f66ccb4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,7 +23,7 @@ export interface FastifyBasicAuthOptions { req: FastifyRequest, reply: FastifyReply, done: (err?: Error) => void - ): void | Promise; + ): Error | void | Promise; authenticate?: boolean | { realm: string }; header?: string; } From 00ea33a91da55bcfa098a680c00edc7e996121f1 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Thu, 16 Sep 2021 10:48:44 +0200 Subject: [PATCH 2/4] Fix type Co-authored-by: KaKa --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index f66ccb4..2a3850b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,7 +23,7 @@ export interface FastifyBasicAuthOptions { req: FastifyRequest, reply: FastifyReply, done: (err?: Error) => void - ): Error | void | Promise; + ): void | Promise; authenticate?: boolean | { realm: string }; header?: string; } From ec8622d44d2381ab58da7c247b2f5ca296b1e9db Mon Sep 17 00:00:00 2001 From: Philipp A Date: Thu, 16 Sep 2021 11:04:19 +0200 Subject: [PATCH 3/4] Ensure correct return type --- index.test-d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/index.test-d.ts b/index.test-d.ts index 3ed19b4..a8f9648 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -17,6 +17,7 @@ app.register(fastifyBasicAuth, { expectType(password) expectType(req) expectType(reply) + if (Math.random() > 0.5) return new Error() }, header: 'x-forwarded-authorization' }) From c733a1f4b5d63d217f3e937b2a48dc54cc48e7e9 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Thu, 16 Sep 2021 11:20:18 +0200 Subject: [PATCH 4/4] tighter interface --- index.d.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2a3850b..1c25682 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,13 +17,22 @@ declare module 'fastify' { } export interface FastifyBasicAuthOptions { - validate( - username: string, - password: string, - req: FastifyRequest, - reply: FastifyReply, - done: (err?: Error) => void - ): void | Promise; + validate: ( + ( + username: string, + password: string, + req: FastifyRequest, + reply: FastifyReply, + ) => Promise + ) | ( + ( + username: string, + password: string, + req: FastifyRequest, + reply: FastifyReply, + done: (err?: Error) => void + ) => void + ); authenticate?: boolean | { realm: string }; header?: string; }