resolvers icon indicating copy to clipboard operation
resolvers copied to clipboard

typescript problem in AJV resolver

Open MshHooman opened this issue 1 year ago • 3 comments

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

MshHooman avatar Jan 10 '24 08:01 MshHooman

also getting this issue

m4dhead avatar Jan 15 '24 13:01 m4dhead

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

Rozamo avatar Jun 27 '24 08:06 Rozamo

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

jorisre avatar Jul 03 '24 07:07 jorisre