Skip to content

Commit

Permalink
Fix: response type of serialize method in FastifyReply interface (#3754)
Browse files Browse the repository at this point in the history
  • Loading branch information
floratmin committed Mar 6, 2022
1 parent 91f6b42 commit dfae6a9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/types/reply.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RawServerDefault, RawReplyDefaultExpression, ContextConfigDefault } fro
import { FastifyLoggerInstance } from '../../types/logger'
import { RouteGenericInterface } from '../../types/route'
import { FastifyInstance } from '../../types/instance'
import { Buffer } from 'buffer'

const getHandler: RouteHandlerMethod = function (_request, reply) {
expectType<RawReplyDefaultExpression>(reply.raw)
Expand All @@ -28,7 +29,7 @@ const getHandler: RouteHandlerMethod = function (_request, reply) {
expectType<() => number>(reply.getResponseTime)
expectType<(contentType: string) => FastifyReply>(reply.type)
expectType<(fn: (payload: any) => string) => FastifyReply>(reply.serializer)
expectType<(payload: any) => string>(reply.serialize)
expectType<(payload: any) => string | ArrayBuffer | Buffer>(reply.serialize)
expectType<(fulfilled: () => void, rejected: (err: Error) => void) => void>(reply.then)
expectType<FastifyInstance>(reply.server)
}
Expand Down
3 changes: 2 additions & 1 deletion types/reply.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FastifyRequest } from './request'
import { RouteGenericInterface } from './route'
import { FastifyInstance } from './instance'
import { FastifySchema } from './schema'
import { Buffer } from 'buffer'

export interface ReplyGenericInterface {
Reply?: ReplyDefault;
Expand Down Expand Up @@ -52,6 +53,6 @@ export interface FastifyReply<
getResponseTime(): number;
type(contentType: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
serializer(fn: (payload: any) => string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
serialize(payload: any): string;
serialize(payload: any): string | ArrayBuffer | Buffer;
then(fulfilled: () => void, rejected: (err: Error) => void): void;
}

0 comments on commit dfae6a9

Please sign in to comment.