Skip to content

Commit

Permalink
add missing 'validationContext' field to FastifyError type (#4363)
Browse files Browse the repository at this point in the history
* fix(types): add missing 'validationContext' field to FastifyError type

* test(types): add tests checking 'validation' and 'validationContext' fields of Fa
stifyError type

* refactor(types): clarify 'validationContext' type with union

Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>

* test(types): add additional assertions for 'validationContext' field

Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
  • Loading branch information
jakubburzynski and Eomm committed Oct 26, 2022
1 parent 1ae1ec2 commit 65d1a32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 65d1a32

Please sign in to comment.