Skip to content

Commit

Permalink
fix(route): type RouteShorthandMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Nov 10, 2023
1 parent af7bef6 commit ed4dd44
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions test/types/logger.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ serverWithPino.route({
}
})

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

const serverWithLogOptions = fastify<
Server,
IncomingMessage,
Expand Down
16 changes: 8 additions & 8 deletions types/instance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ export interface FastifyInstance<
const SchemaCompiler extends FastifySchema = FastifySchema,
>(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>): 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>;
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 ed4dd44

Please sign in to comment.