ajv
ajv copied to clipboard
Migration from v6 to v8: ValidationError isn't exposed anymore
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.
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?
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.
ok, let's export both error classes that Ajv defines, from all 4 Ajv classes.
@epoberezkin Done in #1840
Also having this issue, is there anything I can do to help this over the line?
For anyone finding this, I regressed the install back to 6.12.6 in the short term and its working.
The classes you are missing can be imported from dist/compile/ref_error and dist/runtime/validation_error.