-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: typings with
react-hook-form@7.15.0
(#233)
* Fix yupResolver typings * Fix other resolvers typings * Upgrade `react-hook-form` * Fix typo * Infer field values from zod schema * Infer field values from io-ts decoder * Infer field values from yup schema * Infer field values from typanion validator * Infer field values from superstruct struct * Fix context type * Add nested value
- Loading branch information
1 parent
8e7e789
commit 10ba224
Showing
27 changed files
with
125 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { | ||
FieldValues, | ||
ResolverOptions, | ||
ResolverResult, | ||
UnpackNestedValue, | ||
} from 'react-hook-form'; | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
import { FieldValues, ResolverOptions, ResolverResult } 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, | ||
) => <TFieldValues extends FieldValues, TContext>( | ||
values: UnpackNestedValue<TFieldValues>, | ||
export type Resolver = < | ||
TFieldValues extends FieldValues, | ||
TContext extends object = object, | ||
>( | ||
schema: Struct<TFieldValues, any>, | ||
factoryOptions?: Options, | ||
) => ( | ||
values: unknown, | ||
context: TContext | undefined, | ||
options: ResolverOptions<TFieldValues>, | ||
) => ResolverResult<TFieldValues>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
import type { | ||
FieldValues, | ||
ResolverOptions, | ||
ResolverResult, | ||
UnpackNestedValue, | ||
} from 'react-hook-form'; | ||
import { ValidationState, AnyStrictValidator} from 'typanion' | ||
import { ValidationState, StrictValidator } from 'typanion'; | ||
|
||
type ValidateOptions = Pick<ValidationState, 'coercions' | 'coercion'> | ||
type ValidateOptions = Pick<ValidationState, 'coercions' | 'coercion'>; | ||
|
||
type RHFResolver = <TFieldValues extends FieldValues, TContext>( | ||
values: UnpackNestedValue<TFieldValues>, | ||
type RHFResolver< | ||
TFieldValues extends FieldValues, | ||
TInput = unknown, | ||
TContext extends Object = object, | ||
> = ( | ||
values: TInput, | ||
context: TContext | undefined, | ||
options: ResolverOptions<TFieldValues>, | ||
) => ResolverResult<TFieldValues>; | ||
|
||
export type Resolver = <UnknownValidator extends AnyStrictValidator>( | ||
validator: UnknownValidator, | ||
export type Resolver = < | ||
TInput extends FieldValues = FieldValues, | ||
TFieldValues extends TInput = TInput, | ||
TContext extends object = object, | ||
>( | ||
validator: StrictValidator<TInput, TFieldValues>, | ||
validatorOptions?: ValidateOptions, | ||
)=> RHFResolver | ||
) => RHFResolver<TFieldValues, TInput, TContext>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.