Skip to content

Commit e6fc67d

Browse files
committed
improve type
1 parent 9e8c864 commit e6fc67d

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)