Skip to content

Commit c68b283

Browse files
authored
Merge pull request #2 from react-hook-form/improve-type
improve type
2 parents 81f293f + e6fc67d commit c68b283

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as React from 'react';
22
import { useFormContext } from 'react-hook-form';
3+
import { FieldError } from 'react-hook-form/dist/types';
34

4-
type ErrorFields = Record<string, { message?: string; type: string }>;
5+
type ErrorFields = Record<string, FieldError>;
6+
type ErrorMessages<Errors> = Partial<Record<keyof Errors, string>>;
57

68
const RHFError = <Errors extends ErrorFields, Name extends keyof Errors>({
79
as,
@@ -12,7 +14,7 @@ const RHFError = <Errors extends ErrorFields, Name extends keyof Errors>({
1214
as?: React.ReactElement;
1315
errors?: Errors;
1416
name: Name;
15-
messages?: Record<string, string>;
17+
messages?: ErrorMessages<Errors>;
1618
}) => {
1719
const methods = useFormContext();
1820
const errors = errorsFromProps || (methods.errors as Errors);

0 commit comments

Comments
 (0)