Skip to content

Commit

Permalink
fix: compile error with UnpackNestedValue BREAKING CHANGE: This chang…
Browse files Browse the repository at this point in the history
…e will update package dependency with react-hook-form to 7.33.0 above
  • Loading branch information
bluebill1049 authored Jun 24, 2022
1 parent 7951951 commit 52a6e07
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 37 deletions.
3 changes: 1 addition & 2 deletions ajv/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';
import * as Ajv from 'ajv';

Expand All @@ -11,7 +10,7 @@ export type Resolver = <T>(
schemaOptions?: Ajv.Options,
factoryOptions?: { mode?: 'async' | 'sync' },
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
3 changes: 1 addition & 2 deletions class-validator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';
import { ValidatorOptions } from 'class-validator';
import { ClassConstructor } from 'class-transformer';
Expand All @@ -12,7 +11,7 @@ export type Resolver = <T extends { [_: string]: any }>(
schemaOptions?: ValidatorOptions,
resolverOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; },
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
3 changes: 1 addition & 2 deletions computed-types/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type {
FieldValues,
ResolverResult,
UnpackNestedValue,
ResolverOptions,
} from 'react-hook-form';

export type Resolver = (
schema: any,
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
3 changes: 1 addition & 2 deletions io-ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';

export type Resolver = <T, TFieldValues, TContext>(
codec: t.Decoder<FieldValues, T>,
) => (
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
_context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => ResolverResult<TFieldValues>;
Expand Down
3 changes: 1 addition & 2 deletions joi/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';
import type { AsyncValidationOptions, Schema } from 'joi';

Expand All @@ -11,7 +10,7 @@ export type Resolver = <T extends Schema>(
schemaOptions?: AsyncValidationOptions,
factoryOptions?: { mode?: 'async' | 'sync' },
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
4 changes: 2 additions & 2 deletions nope/src/nope.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,7 +15,7 @@ const parseErrors = (
if (typeof error === 'string') {
acc[_path] = {
message: error,
};
} as FieldError;
} else {
parseErrors(error, acc, _path);
}
Expand Down
3 changes: 1 addition & 2 deletions nope/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';
import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject';

Expand All @@ -14,7 +13,7 @@ export type Resolver = <T extends NopeObject>(
schemaOptions?: ValidateOptions,
resolverOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; },
) => <TFieldValues extends FieldValues, TContext extends Context>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => ResolverResult<TFieldValues>;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/toNestError.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {
set,
get,
FieldError,
FieldErrors,
Field,
ResolverOptions,
} from 'react-hook-form';
import { validateFieldsNatively } from './validateFieldsNatively';

export const toNestError = <TFieldValues>(
errors: Record<string, FieldError>,
errors: FieldErrors,
options: ResolverOptions<TFieldValues>,
): FieldErrors<TFieldValues> => {
options.shouldUseNativeValidation && validateFieldsNatively(errors, options);
Expand Down
6 changes: 3 additions & 3 deletions src/validateFieldsNatively.ts
Original file line number Diff line number Diff line change
@@ -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<string, FieldError>) => {
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) || '');
Expand All @@ -13,7 +13,7 @@ const setCustomValidity = (ref: Ref, fieldPath: string, errors: Record<string, F

// Native validation (web only)
export const validateFieldsNatively = <TFieldValues>(
errors: Record<string, FieldError>,
errors: FieldErrors,
options: ResolverOptions<TFieldValues>,
): void => {

Expand Down
5 changes: 2 additions & 3 deletions superstruct/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';
import { validate, Struct } from 'superstruct';

type Options = Parameters<typeof validate>[2];

export type Resolver = <T extends Struct<any, any>>(
schema: T,
factoryOtions?: Options,
options?: Options,
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => ResolverResult<TFieldValues>;
4 changes: 2 additions & 2 deletions typanion/src/typanion.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -8,7 +8,7 @@ const parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {

acc[e[0].slice(1)] = {
message: e[1].trim(),
};
} as FieldError;

return acc;
}, parsedErrors);
Expand Down
3 changes: 1 addition & 2 deletions typanion/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import type {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';
import { ValidationState, AnyStrictValidator} from 'typanion'

type ValidateOptions = Pick<ValidationState, 'coercions' | 'coercion'>

type RHFResolver = <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => ResolverResult<TFieldValues>;
Expand Down
3 changes: 1 addition & 2 deletions vest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
FieldValues,
ResolverOptions,
ResolverResult,
UnpackNestedValue,
} from 'react-hook-form';
import * as Vest from 'vest';

Expand All @@ -13,7 +12,7 @@ export type Resolver = (
schemaOptions?: never,
factoryOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; },
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions yup/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,7 +15,7 @@ export type Resolver = <T extends Yup.AnyObjectSchema | Lazy<any>>(
schemaOptions?: Options<T>,
factoryOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; },
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
3 changes: 1 addition & 2 deletions zod/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
FieldValues,
ResolverResult,
UnpackNestedValue,
ResolverOptions,
} from 'react-hook-form';
import { z } from 'zod';
Expand All @@ -21,7 +20,7 @@ export type Resolver = <T extends z.Schema<any, any>>(
rawValues?: boolean;
},
) => <TFieldValues extends FieldValues, TContext>(
values: UnpackNestedValue<TFieldValues>,
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;

0 comments on commit 52a6e07

Please sign in to comment.