Skip to content

Commit

Permalink
fix: type FastifyInstance['route'] and RouteShorthandMethod (#5155)
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Dec 2, 2023
1 parent 1891f24 commit f808f96
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
14 changes: 14 additions & 0 deletions test/types/logger.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ P.Logger

expectType<P.Logger>(serverWithPino.log)

serverWithPino.route({
method: 'GET',
url: '/',
handler (request) {
expectType<P.Logger>(this.log)
expectType<P.Logger>(request.log)
}
})

serverWithPino.get('/', function (request) {
expectType<P.Logger>(this.log)
expectType<P.Logger>(request.log)
})

const serverWithLogOptions = fastify<
Server,
IncomingMessage,
Expand Down
20 changes: 10 additions & 10 deletions types/instance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ export interface FastifyInstance<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
const SchemaCompiler extends FastifySchema = FastifySchema,
>(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
head: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
post: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
put: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
delete: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
options: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
patch: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
all: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
>(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
head: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
post: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
put: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
delete: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
options: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
patch: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;
all: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider, Logger>;

hasRoute<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
Expand Down
7 changes: 4 additions & 3 deletions types/route.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,18 @@ export interface RouteShorthandMethod<
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
Logger extends FastifyBaseLogger = FastifyBaseLogger
> {
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>(
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(
path: string,
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>,
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>(
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(
path: string,
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>(
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(
path: string,
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
Expand Down

0 comments on commit f808f96

Please sign in to comment.