Skip to content

Commit

Permalink
fix: Add types to server properties (#4100)
Browse files Browse the repository at this point in the history
* add types to validatorCompiler & serializerCompiler

* tests for the type addition
  • Loading branch information
TommyDew42 committed Jul 1, 2022
1 parent c525e67 commit 7bbd665
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/types/instance.test-d.ts
Expand Up @@ -11,7 +11,7 @@ import { HookHandlerDoneFunction } from '../../types/hooks'
import { FastifyReply } from '../../types/reply'
import { FastifyRequest } from '../../types/request'
import { DefaultRoute } from '../../types/route'
import { FastifySchemaControllerOptions } from '../../types/schema'
import { FastifySchemaControllerOptions, FastifySchemaCompiler, FastifySerializerCompiler } from '../../types/schema'

const server = fastify()

Expand Down Expand Up @@ -325,3 +325,6 @@ expectType<void>(server.addConstraintStrategy(versionConstraintStrategy))
expectType<boolean>(server.hasConstraintStrategy(versionConstraintStrategy.name))

expectAssignable<DefaultRoute<RawRequestDefaultExpression, RawReplyDefaultExpression>>(server.getDefaultRoute())

expectType<FastifySchemaCompiler<any> | undefined>(server.validatorCompiler)
expectType<FastifySerializerCompiler<any> | undefined>(server.serializerCompiler)
10 changes: 10 additions & 0 deletions types/instance.d.ts
Expand Up @@ -550,11 +550,21 @@ export interface FastifyInstance<
handler: (this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, error: TError, request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfigDefault, SchemaCompiler, TypeProvider>) => any | Promise<any>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

/**
* Fastify schema validator for all routes.
*/
validatorCompiler: FastifySchemaCompiler<any> | undefined;

/**
* Set the schema validator for all routes.
*/
setValidatorCompiler<T = FastifySchema>(schemaCompiler: FastifySchemaCompiler<T>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

/**
* Fastify schema serializer for all routes.
*/
serializerCompiler: FastifySerializerCompiler<any> | undefined;

/**
* Set the schema serializer for all routes.
*/
Expand Down

0 comments on commit 7bbd665

Please sign in to comment.