Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: FieldErrors type doesn't support the "root" property #11883

Closed
1 task done
peguerosdc opened this issue May 14, 2024 · 1 comment
Closed
1 task done

issue: FieldErrors type doesn't support the "root" property #11883

peguerosdc opened this issue May 14, 2024 · 1 comment

Comments

@peguerosdc
Copy link

peguerosdc commented May 14, 2024

Version Number

7.51.4

Codesandbox/Expo snack

(EDIT: link was too long, sorry)

https://codesandbox.io/p/sandbox/typebox-experiments-forked-fsw7mn

Steps to reproduce

Try to create custom errors that match the FieldErrors<T> signature:

import { FieldErrors } from "react-hook-form";

type GroupsSchemaType = {
  name: string;
  checked: boolean;
}[];

const handleErrors = (): FieldErrors<GroupsSchemaType> => {
  return { root: { message: "m", type: "" } };
};

Expected behaviour

I should be able to set a root error for the array field without typescript complaining.

What browsers are you seeing the problem on?

No response

Relevant log output

Type '{ message: string; type: string; }' is not assignable to type 'Record<string, Partial<{ type: string | number; message: string; }>> & Partial<{ type: string | number; message: string; }>'.
  Type '{ message: string; type: string; }' is not assignable to type 'Record<string, Partial<{ type: string | number; message: string; }>>'.
    Property 'message' is incompatible with index signature.
      Type 'string' has no properties in common with type 'Partial<{ type: string | number; message: string; }>'.typescript(2322)
errors.d.ts(33, 5): The expected type comes from property 'root' which is declared here on type 'FieldErrors<GroupsSchemaType>'

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049 bluebill1049 added the status: under investigation aware of this issue and pending for investigation label May 18, 2024
@bluebill1049
Copy link
Member

type GroupsSchemaType = {
  name: string;
  checked: boolean;
};

const handleErrors: FieldErrors<GroupsSchemaType> = {
  root: {
    test: {
      type: 'string',
      message: 'data',
    },
  },
};

it's asking for a Recoard

@bluebill1049 bluebill1049 removed the status: under investigation aware of this issue and pending for investigation label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants