From 52a6e07876a677566a71aad7d66cbd6f9fa59ecc Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 25 Jun 2022 09:25:28 +1000 Subject: [PATCH] fix: compile error with UnpackNestedValue BREAKING CHANGE: This change will update package dependency with react-hook-form to 7.33.0 above --- ajv/src/types.ts | 3 +-- class-validator/src/types.ts | 3 +-- computed-types/src/types.ts | 3 +-- io-ts/src/types.ts | 3 +-- joi/src/types.ts | 3 +-- nope/src/nope.ts | 4 ++-- nope/src/types.ts | 3 +-- package.json | 2 +- src/toNestError.ts | 3 +-- src/validateFieldsNatively.ts | 6 +++--- superstruct/src/types.ts | 5 ++--- typanion/src/typanion.ts | 4 ++-- typanion/src/types.ts | 3 +-- vest/src/types.ts | 3 +-- yarn.lock | 8 ++++---- yup/src/types.ts | 3 +-- zod/src/types.ts | 3 +-- 17 files changed, 25 insertions(+), 37 deletions(-) diff --git a/ajv/src/types.ts b/ajv/src/types.ts index fa328482..402fb3a1 100644 --- a/ajv/src/types.ts +++ b/ajv/src/types.ts @@ -2,7 +2,6 @@ import { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import * as Ajv from 'ajv'; @@ -11,7 +10,7 @@ export type Resolver = ( schemaOptions?: Ajv.Options, factoryOptions?: { mode?: 'async' | 'sync' }, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => Promise>; diff --git a/class-validator/src/types.ts b/class-validator/src/types.ts index 2303e021..77e3f96b 100644 --- a/class-validator/src/types.ts +++ b/class-validator/src/types.ts @@ -2,7 +2,6 @@ import { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import { ValidatorOptions } from 'class-validator'; import { ClassConstructor } from 'class-transformer'; @@ -12,7 +11,7 @@ export type Resolver = ( schemaOptions?: ValidatorOptions, resolverOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; }, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => Promise>; diff --git a/computed-types/src/types.ts b/computed-types/src/types.ts index 1f7b25ce..fcb8c4c7 100644 --- a/computed-types/src/types.ts +++ b/computed-types/src/types.ts @@ -1,14 +1,13 @@ import type { FieldValues, ResolverResult, - UnpackNestedValue, ResolverOptions, } from 'react-hook-form'; export type Resolver = ( schema: any, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => Promise>; diff --git a/io-ts/src/types.ts b/io-ts/src/types.ts index 06d7cc5e..044697dc 100644 --- a/io-ts/src/types.ts +++ b/io-ts/src/types.ts @@ -4,13 +4,12 @@ import { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; export type Resolver = ( codec: t.Decoder, ) => ( - values: UnpackNestedValue, + values: TFieldValues, _context: TContext | undefined, options: ResolverOptions, ) => ResolverResult; diff --git a/joi/src/types.ts b/joi/src/types.ts index ede151c1..8047b81a 100644 --- a/joi/src/types.ts +++ b/joi/src/types.ts @@ -2,7 +2,6 @@ import { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import type { AsyncValidationOptions, Schema } from 'joi'; @@ -11,7 +10,7 @@ export type Resolver = ( schemaOptions?: AsyncValidationOptions, factoryOptions?: { mode?: 'async' | 'sync' }, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => Promise>; diff --git a/nope/src/nope.ts b/nope/src/nope.ts index 2d2bcfd4..c212e6cc 100644 --- a/nope/src/nope.ts +++ b/nope/src/nope.ts @@ -1,4 +1,4 @@ -import type { FieldErrors } from 'react-hook-form'; +import type {FieldError, FieldErrors} from 'react-hook-form'; import { toNestError, validateFieldsNatively } from '@hookform/resolvers'; import type { ShapeErrors } from 'nope-validator/lib/cjs/types'; import type { Resolver } from './types'; @@ -15,7 +15,7 @@ const parseErrors = ( if (typeof error === 'string') { acc[_path] = { message: error, - }; + } as FieldError; } else { parseErrors(error, acc, _path); } diff --git a/nope/src/types.ts b/nope/src/types.ts index ef2ef658..6a927107 100644 --- a/nope/src/types.ts +++ b/nope/src/types.ts @@ -2,7 +2,6 @@ import type { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject'; @@ -14,7 +13,7 @@ export type Resolver = ( schemaOptions?: ValidateOptions, resolverOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; }, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => ResolverResult; diff --git a/package.json b/package.json index 7523df29..45ae8edd 100644 --- a/package.json +++ b/package.json @@ -205,7 +205,7 @@ "prettier": "^2.5.1", "react": "^17.0.2", "react-dom": "^17.0.2", - "react-hook-form": "7.29.0", + "react-hook-form": "^7.33.0", "reflect-metadata": "^0.1.13", "superstruct": "^0.15.3", "ts-jest": "^27.1.3", diff --git a/src/toNestError.ts b/src/toNestError.ts index a5dfe553..09dd8d3e 100644 --- a/src/toNestError.ts +++ b/src/toNestError.ts @@ -1,7 +1,6 @@ import { set, get, - FieldError, FieldErrors, Field, ResolverOptions, @@ -9,7 +8,7 @@ import { import { validateFieldsNatively } from './validateFieldsNatively'; export const toNestError = ( - errors: Record, + errors: FieldErrors, options: ResolverOptions, ): FieldErrors => { options.shouldUseNativeValidation && validateFieldsNatively(errors, options); diff --git a/src/validateFieldsNatively.ts b/src/validateFieldsNatively.ts index 640799f6..4eda8a45 100644 --- a/src/validateFieldsNatively.ts +++ b/src/validateFieldsNatively.ts @@ -1,8 +1,8 @@ import { - get, FieldError, ResolverOptions, Ref + get, FieldError, ResolverOptions, Ref, FieldErrors } from 'react-hook-form'; -const setCustomValidity = (ref: Ref, fieldPath: string, errors: Record) => { +const setCustomValidity = (ref: Ref, fieldPath: string, errors: FieldErrors) => { if (ref && 'reportValidity' in ref) { const error = get(errors, fieldPath) as FieldError | undefined; ref.setCustomValidity((error && error.message) || ''); @@ -13,7 +13,7 @@ const setCustomValidity = (ref: Ref, fieldPath: string, errors: Record( - errors: Record, + errors: FieldErrors, options: ResolverOptions, ): void => { diff --git a/superstruct/src/types.ts b/superstruct/src/types.ts index fc48c577..51d3d316 100644 --- a/superstruct/src/types.ts +++ b/superstruct/src/types.ts @@ -2,7 +2,6 @@ import { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import { validate, Struct } from 'superstruct'; @@ -10,9 +9,9 @@ type Options = Parameters[2]; export type Resolver = >( schema: T, - factoryOtions?: Options, + options?: Options, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => ResolverResult; diff --git a/typanion/src/typanion.ts b/typanion/src/typanion.ts index 221eca8e..432f4a25 100644 --- a/typanion/src/typanion.ts +++ b/typanion/src/typanion.ts @@ -1,4 +1,4 @@ -import type { FieldErrors } from 'react-hook-form'; +import type {FieldError, FieldErrors} from 'react-hook-form'; import { toNestError, validateFieldsNatively } from '@hookform/resolvers'; import type { Resolver } from './types'; @@ -8,7 +8,7 @@ const parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => { acc[e[0].slice(1)] = { message: e[1].trim(), - }; + } as FieldError; return acc; }, parsedErrors); diff --git a/typanion/src/types.ts b/typanion/src/types.ts index d77e561e..4fdbc232 100644 --- a/typanion/src/types.ts +++ b/typanion/src/types.ts @@ -2,14 +2,13 @@ import type { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import { ValidationState, AnyStrictValidator} from 'typanion' type ValidateOptions = Pick type RHFResolver = ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => ResolverResult; diff --git a/vest/src/types.ts b/vest/src/types.ts index f08fe7a6..1fa52c0a 100644 --- a/vest/src/types.ts +++ b/vest/src/types.ts @@ -2,7 +2,6 @@ import { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import * as Vest from 'vest'; @@ -13,7 +12,7 @@ export type Resolver = ( schemaOptions?: never, factoryOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; }, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => Promise>; diff --git a/yarn.lock b/yarn.lock index a1d62a2a..ac5477c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5775,10 +5775,10 @@ react-dom@^17.0.2: object-assign "^4.1.1" scheduler "^0.20.2" -react-hook-form@7.29.0: - version "7.29.0" - resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.29.0.tgz#5e7e41a483b70731720966ed8be52163ea1fecf1" - integrity sha512-NcJqWRF6el5HMW30fqZRt27s+lorvlCCDbTpAyHoodQeYWXgQCvZJJQLC1kRMKdrJknVH0NIg3At6TUzlZJFOQ== +react-hook-form@^7.33.0: + version "7.33.0" + resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.33.0.tgz#44a87ddd630f00ebeb0f15aa978f69ca74b8a77b" + integrity sha512-h8XoeUHQs1Snx1s/sSvM+eVTSKkWQt8TcrbL+3/Rt5gugxpy4ueL5ZZkubffyNpUyyTz0qM0kwOi2c+JgGTjLA== react-is@^17.0.1: version "17.0.2" diff --git a/yup/src/types.ts b/yup/src/types.ts index 90155f2b..7386abcb 100644 --- a/yup/src/types.ts +++ b/yup/src/types.ts @@ -2,7 +2,6 @@ import { FieldValues, ResolverOptions, ResolverResult, - UnpackNestedValue, } from 'react-hook-form'; import * as Yup from 'yup'; import type Lazy from 'yup/lib/Lazy'; @@ -16,7 +15,7 @@ export type Resolver = >( schemaOptions?: Options, factoryOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; }, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => Promise>; diff --git a/zod/src/types.ts b/zod/src/types.ts index 4f053916..e340bbb0 100644 --- a/zod/src/types.ts +++ b/zod/src/types.ts @@ -1,7 +1,6 @@ import { FieldValues, ResolverResult, - UnpackNestedValue, ResolverOptions, } from 'react-hook-form'; import { z } from 'zod'; @@ -21,7 +20,7 @@ export type Resolver = >( rawValues?: boolean; }, ) => ( - values: UnpackNestedValue, + values: TFieldValues, context: TContext | undefined, options: ResolverOptions, ) => Promise>;