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

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

Open
Ginden opened this issue Nov 29, 2021 · 7 comments
Open

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

Ginden opened this issue Nov 29, 2021 · 7 comments

Comments

@Ginden
Copy link

Ginden commented Nov 29, 2021

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.

@epoberezkin
Copy link
Member

epoberezkin commented Dec 8, 2021

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?

@Ginden
Copy link
Author

Ginden commented Dec 9, 2021

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.

@epoberezkin
Copy link
Member

epoberezkin commented Dec 10, 2021

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

@Ginden
Copy link
Author

Ginden commented Dec 10, 2021

@epoberezkin Done in #1840

@dannyb648
Copy link
Contributor

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

@dannyb648
Copy link
Contributor

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

@epoberezkin
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants