Skip to content

Commit

Permalink
types: nullish error types in callback function's parameter for `afte…
Browse files Browse the repository at this point in the history
…r` and `ready` method (#5191)

* types: nullish error types in callback function's parameter

* types: update `ready` method's parameter type

Co-authored-by: KaKa <23028015+climba03003@users.noreply.github.com>

* types: add tests for `after` & `ready` methods

---------

Co-authored-by: KaKa <23028015+climba03003@users.noreply.github.com>
  • Loading branch information
nokazn and climba03003 committed Dec 12, 2023
1 parent 7c778af commit b3a0e67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions test/types/instance.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ expectNotDeprecated(server.listen({ port: 3000, host: '0.0.0.0', backlog: 42 },
expectNotDeprecated(server.listen({ port: 3000, host: '0.0.0.0', backlog: 42, exclusive: true }, () => {}))
expectNotDeprecated(server.listen({ port: 3000, host: '::/0', ipv6Only: true }, () => {}))

// test after method
expectAssignable<FastifyInstance>(server.after())
expectAssignable<FastifyInstance>(server.after((err) => {
expectType<Error | null>(err)
}))

// test ready method
expectAssignable<FastifyInstance>(server.ready())
expectAssignable<FastifyInstance>(server.ready((err) => {
expectType<Error | null>(err)
}))

expectAssignable<void>(server.routing({} as RawRequestDefaultExpression, {} as RawReplyDefaultExpression))

expectType<FastifyInstance>(fastify().get<RouteGenericInterface, { contextKey: string }>('/', {
Expand Down
4 changes: 2 additions & 2 deletions types/instance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface FastifyInstance<
getSchemas(): Record<string, unknown>;

after(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>;
after(afterListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
after(afterListener: (err: Error | null) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

close(): Promise<undefined>;
close(closeListener: () => void): undefined;
Expand Down Expand Up @@ -190,7 +190,7 @@ export interface FastifyInstance<
listen(port: number | string, address?: string, backlog?: number): Promise<string>;

ready(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>;
ready(readyListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
ready(readyListener: (err: Error | null) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>>;

Expand Down

0 comments on commit b3a0e67

Please sign in to comment.