ajv icon indicating copy to clipboard operation
ajv copied to clipboard

Migration from v6 to v8: ValidationError isn't exposed anymore

Open Ginden opened this issue 3 years ago • 7 comments

What version of Ajv are you using? Does the issue happen if you use the latest version?

I was using 6, I wanted to migrate to 8.

Ajv options object

N/A

JSON Schema

N/A

Your code

In v6 I could write code like:

import {ValidationError} from 'ajv';
function formatAjvError(error: ValidationError): CustomErrorDto {}

In v8 I must write:

import Ajv from 'ajv';
function formatAjvError(error: InstanceType<typeof Ajv['ValidationError']>): CustomErrorDto {}

This is unnecessary verbose.

What results did you expect?

ValidationError is directly exported from ajv module.

Are you going to resolve the issue?

Yes, I can make PR for that.

Ginden avatar Nov 29 '21 14:11 Ginden

So the error classes are defined as static members on the core class, but not on the subclasses that the users use, and you suggest to add static members to these subclasses as well - do I understand it correctly?

epoberezkin avatar Dec 08 '21 23:12 epoberezkin

do I understand it correctly?

No. My issue that it's currently impossible import eg. ValidationError, because it isn't exported from ajv module.

import {ValidationError} from 'ajv';

I updated issue to better reflect intended use.

Ginden avatar Dec 09 '21 14:12 Ginden

ok, let's export both error classes that Ajv defines, from all 4 Ajv classes.

epoberezkin avatar Dec 10 '21 11:12 epoberezkin

@epoberezkin Done in #1840

Ginden avatar Dec 10 '21 15:12 Ginden

Also having this issue, is there anything I can do to help this over the line?

dannyb648 avatar Jun 24 '22 15:06 dannyb648

For anyone finding this, I regressed the install back to 6.12.6 in the short term and its working.

dannyb648 avatar Jun 26 '22 18:06 dannyb648

The classes you are missing can be imported from dist/compile/ref_error and dist/runtime/validation_error.

epoberezkin avatar Jun 26 '22 22:06 epoberezkin