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

add missing 'validationContext' field to FastifyError type #4363

Merged
merged 4 commits into from Oct 26, 2022
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
1 change: 1 addition & 0 deletions fastify.d.ts
Expand Up @@ -183,6 +183,7 @@ type TrustProxyFunction = (address: string, hop: number) => boolean
declare module '@fastify/error' {
interface FastifyError {
validation?: ValidationResult[];
validationContext?: 'body' | 'headers' | 'parameters' | 'querystring';
}
}

Expand Down
9 changes: 8 additions & 1 deletion test/types/fastify.test-d.ts
Expand Up @@ -10,7 +10,8 @@ import fastify, {
InjectOptions, FastifyBaseLogger,
RouteGenericInterface,
ValidationResult,
FastifyErrorCodes
FastifyErrorCodes,
FastifyError
} from '../../fastify'
import { ErrorObject as AjvErrorObject } from 'ajv'
import * as http from 'http'
Expand Down Expand Up @@ -235,6 +236,12 @@ const ajvErrorObject: AjvErrorObject = {
}
expectAssignable<ValidationResult>(ajvErrorObject)

expectAssignable<FastifyError['validation']>([ajvErrorObject])
expectAssignable<FastifyError['validationContext']>('body')
expectAssignable<FastifyError['validationContext']>('headers')
expectAssignable<FastifyError['validationContext']>('parameters')
expectAssignable<FastifyError['validationContext']>('querystring')

const routeGeneric: RouteGenericInterface = {}
expectType<unknown>(routeGeneric.Body)
expectType<unknown>(routeGeneric.Headers)
Expand Down