Skip to content

Commit

Permalink
Add test for config type in RouteShorthandOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianValente authored and mcollina committed May 16, 2024
1 parent f56b7c7 commit 3ff1c54
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/types/route.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ declare module '../../fastify' {
interface FastifyContextConfig {
foo: string;
bar: number;
includeMessage?: boolean;
}

interface FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger, RequestType> {
message: ContextConfig extends { includeMessage: true }
? string
: null;
}
}

Expand All @@ -36,6 +43,22 @@ const routeHandlerWithReturnValue: RouteHandlerMethod = function (request, reply
return reply.send()
}

fastify().get(
'/',
{ config: { foo: 'bar', bar: 100, includeMessage: true } },
(req) => {
expectType<string>(req.message)
}
)

fastify().get(
'/',
{ config: { foo: 'bar', bar: 100, includeMessage: false } },
(req) => {
expectType<null>(req.message)
}
)

type LowerCaseHTTPMethods = 'delete' | 'get' | 'head' | 'patch' | 'post' | 'put' |
'options' | 'propfind' | 'proppatch' | 'mkcol' | 'copy' | 'move' | 'lock' |
'unlock' | 'trace' | 'search' | 'mkcalendar' | 'report'
Expand Down

0 comments on commit 3ff1c54

Please sign in to comment.