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

typescript problem in AJV resolver #658

Open
MshHooman opened this issue Jan 10, 2024 · 3 comments
Open

typescript problem in AJV resolver #658

MshHooman opened this issue Jan 10, 2024 · 3 comments

Comments

@MshHooman
Copy link

MshHooman commented Jan 10, 2024

Describe the bug
Hi,
I'm using ajvResolver in my project but face a typescript error that is wrong.

here is my packages:

"@hookform/resolvers": "3.3.4",
"react-hook-form": "^7.0.0",
"typescript": "~5.2.2",
"vite": "^5.0.0",
"@types/react": "^18.2.46",
"@types/react-dom": "^18.2.18",

and this is an example of code that I used:

  const schema = {
    type: 'object',
    properties: {
      password1: {
        type: 'string',
        minLength: 3,
        errorMessage: { minLength: 'password1 field is required' },
      },
      password2: {
        type: 'string',
        minLength: 3,
        errorMessage: { minLength: 'password2 field is required' },
      },
    },
    required: ['password1', 'password2'],
    additionalProperties: false,
  };

  const validation = ajvResolver(schema);

but I face this error from ajvResolver:

Property 'oneOf' is missing in type '{ type: string; properties: { password1: { type: string; minLength: number; errorMessage: { minLength: string; }; }; password2: { type: string; minLength: number; errorMessage: { minLength: string; }; }; }; required: string[]; additionalProperties: boolean; }' but required in type '{ oneOf: readonly UncheckedJSONSchemaType<FormType, false>[]; }'.ts(2345)

so when I add oneOf property the type problem will be solved but as I understand and test in AJV directly ,this property is not required !

  • OS: mac OS Version 14.0
  • Browser chrome
@m4dhead
Copy link

m4dhead commented Jan 15, 2024

also getting this issue

@Rozamo
Copy link

Rozamo commented Jun 27, 2024

Can you try assigning the type JSONSchemaType to your schema as mentioned here. It solved the issue for me.

@jorisre
Copy link
Member

jorisre commented Jul 3, 2024

Can you please provide a minimal reproducible example (e.g. a Codesandbox)?

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

4 participants