From bd0914632a1b26e537b8741487b2451b5c399763 Mon Sep 17 00:00:00 2001 From: jakubburzynski Date: Thu, 20 Oct 2022 15:13:51 +0200 Subject: [PATCH 1/4] fix(types): add missing 'validationContext' field to FastifyError type --- fastify.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/fastify.d.ts b/fastify.d.ts index aa0cc012d2..bc9eea7731 100644 --- a/fastify.d.ts +++ b/fastify.d.ts @@ -183,6 +183,7 @@ type TrustProxyFunction = (address: string, hop: number) => boolean declare module '@fastify/error' { interface FastifyError { validation?: ValidationResult[]; + validationContext?: string; } } From faffca9e7a696aab7268efab8d1bce0ee4fe36f4 Mon Sep 17 00:00:00 2001 From: jakubburzynski Date: Thu, 20 Oct 2022 18:53:05 +0200 Subject: [PATCH 2/4] test(types): add tests checking 'validation' and 'validationContext' fields of Fa stifyError type --- test/types/fastify.test-d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/types/fastify.test-d.ts b/test/types/fastify.test-d.ts index 63f65360c6..f44164bd9f 100644 --- a/test/types/fastify.test-d.ts +++ b/test/types/fastify.test-d.ts @@ -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' @@ -235,6 +236,9 @@ const ajvErrorObject: AjvErrorObject = { } expectAssignable(ajvErrorObject) +expectAssignable([ajvErrorObject]) +expectAssignable("body") + const routeGeneric: RouteGenericInterface = {} expectType(routeGeneric.Body) expectType(routeGeneric.Headers) From 728a6e2069757a31ff03c14715ad4d68ffe6cde9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Burzy=C5=84ski?= <33811303+jakubburzynski@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:42:10 +0200 Subject: [PATCH 3/4] refactor(types): clarify 'validationContext' type with union Co-authored-by: Manuel Spigolon --- fastify.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastify.d.ts b/fastify.d.ts index bc9eea7731..787d9326fb 100644 --- a/fastify.d.ts +++ b/fastify.d.ts @@ -183,7 +183,7 @@ type TrustProxyFunction = (address: string, hop: number) => boolean declare module '@fastify/error' { interface FastifyError { validation?: ValidationResult[]; - validationContext?: string; + validationContext?: "body" | "headers" | "parameters" | "querystring"; } } From d38bb14857427b3295f62b499fbc6daa5ba7c8ce Mon Sep 17 00:00:00 2001 From: jakubburzynski Date: Wed, 26 Oct 2022 11:40:29 +0200 Subject: [PATCH 4/4] test(types): add additional assertions for 'validationContext' field --- fastify.d.ts | 2 +- test/types/fastify.test-d.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fastify.d.ts b/fastify.d.ts index 787d9326fb..759090cd9a 100644 --- a/fastify.d.ts +++ b/fastify.d.ts @@ -183,7 +183,7 @@ type TrustProxyFunction = (address: string, hop: number) => boolean declare module '@fastify/error' { interface FastifyError { validation?: ValidationResult[]; - validationContext?: "body" | "headers" | "parameters" | "querystring"; + validationContext?: 'body' | 'headers' | 'parameters' | 'querystring'; } } diff --git a/test/types/fastify.test-d.ts b/test/types/fastify.test-d.ts index f44164bd9f..eac0a77e4d 100644 --- a/test/types/fastify.test-d.ts +++ b/test/types/fastify.test-d.ts @@ -236,8 +236,11 @@ const ajvErrorObject: AjvErrorObject = { } expectAssignable(ajvErrorObject) -expectAssignable([ajvErrorObject]) -expectAssignable("body") +expectAssignable([ajvErrorObject]) +expectAssignable('body') +expectAssignable('headers') +expectAssignable('parameters') +expectAssignable('querystring') const routeGeneric: RouteGenericInterface = {} expectType(routeGeneric.Body)