Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add routeOptions.config to types #5034

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion test/types/request.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expectAssignable, expectType } from 'tsd'
import fastify, {
ContextConfigDefault,
FastifyContext,
FastifyContextConfig,
FastifyLogFn,
FastifySchema,
FastifyTypeProviderDefault,
Expand All @@ -18,7 +19,7 @@ import { FastifyInstance } from '../../types/instance'
import { FastifyLoggerInstance } from '../../types/logger'
import { FastifyReply } from '../../types/reply'
import { FastifyRequest, RequestRouteOptions } from '../../types/request'
import { RouteGenericInterface } from '../../types/route'
import { FastifyRouteConfig, RouteGenericInterface } from '../../types/route'
import { RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from '../../types/utils'

interface RequestBody {
Expand Down Expand Up @@ -77,6 +78,8 @@ const getHandler: RouteHandler = function (request, _reply) {
expectType<FastifyContext<ContextConfigDefault>>(request.context)
expectType<FastifyContext<ContextConfigDefault>['config']>(request.context.config)
expectType<FastifyContext<ContextConfigDefault>['config']>(request.routeConfig)
expectType<FastifyContext<ContextConfigDefault>['config']>(request.routeOptions.config)
expectType<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>(request.routeOptions.config)
expectType<FastifySchema>(request.routeSchema)

expectType<RequestHeadersDefault & RawRequestDefaultExpression['headers']>(request.headers)
Expand Down
11 changes: 6 additions & 5 deletions types/request.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ErrorObject } from '@fastify/ajv-compiler'
import { FastifyContext } from './context'
import { FastifyContext, FastifyContextConfig } from './context'
import { FastifyInstance } from './instance'
import { FastifyBaseLogger } from './logger'
import { RouteGenericInterface } from './route'
import { RouteGenericInterface, FastifyRouteConfig } from './route'
import { FastifySchema } from './schema'
import { FastifyRequestType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyRequestType } from './type-provider'
import { ContextConfigDefault, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestBodyDefault, RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from './utils'
Expand All @@ -20,15 +20,16 @@ export interface ValidationFunction {
errors?: null | ErrorObject[];
}

export interface RequestRouteOptions {
export interface RequestRouteOptions<ContextConfig = ContextConfigDefault> {
method: string,
url: string,
bodyLimit:number,
attachValidation:boolean,
logLevel:string,
version: string | undefined,
exposeHeadRoute: boolean,
prefixTrailingSlash: string
prefixTrailingSlash: string,
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig
}

/**
Expand Down Expand Up @@ -78,7 +79,7 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
readonly method: string;
readonly routerPath: string;
readonly routerMethod: string;
readonly routeOptions: Readonly<RequestRouteOptions>
readonly routeOptions: Readonly<RequestRouteOptions<ContextConfig>>
readonly is404: boolean;
readonly socket: RawRequest['socket'];

Expand Down