Skip to content

Commit

Permalink
Merge pull request #5 from francisdaigle/feature/add-ts-support
Browse files Browse the repository at this point in the history
Add missing options
  • Loading branch information
hsynlms authored May 21, 2021
2 parents 7fca62b + 6881646 commit 6f80cad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ declare module 'fastify' {
}

declare const fastifyGuard: FastifyPluginCallback<{
errorHandler(
errorHandler?(
result: createHttpError.HttpError,
request: FastifyRequest,
reply: FastifyReply
): any
requestProperty?: string
roleProperty?: string
scopeProperty?: string
}>

export default fastifyGuard
11 changes: 7 additions & 4 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ const fastify = Fastify()

fastify.register(fastifyGuard, {
errorHandler: (result, req, reply) => {
return reply.send('Custom error message')
}
return reply.send('string')
},
requestProperty: 'string',
roleProperty: 'string',
scopeProperty: 'string'
})

;(request: FastifyRequest, reply: FastifyReply) => {
Expand All @@ -26,5 +29,5 @@ fastify.register(fastifyGuard, {
)
}

expectType<preHandlerHookHandler>(fastify.guard.role(['user']))
expectType<preHandlerHookHandler>(fastify.guard.scope(['read']))
expectType<preHandlerHookHandler>(fastify.guard.role(['string']))
expectType<preHandlerHookHandler>(fastify.guard.scope(['string']))

0 comments on commit 6f80cad

Please sign in to comment.