ajv-validator / ajv-validator/ajv-formats

Compatability problem with `ajv`

Open
#122 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
228
Forks
42
PR merge metrics
No merged PRs in 30d

Description

I installed ajv v8 like this:
```
npm i ajv@^8
```

Then I installed ajv-formats:
```
npm i ajv-formats
```

Installed packages in `package.json`:
```
"ajv": "^8.20.0",
"ajv-formats": "^3.0.1",
```

But after writing these lines, it has error:
```
import Ajv from 'ajv';
import addFormats from 'ajv-formats';

// ...

constructor() {
this.ajv = new Ajv({ allErrors: true });
addFormats(this.ajv);
^^^^
}
```

error:
```
Argument of type 'import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/ajv").Ajv' is not assignable to parameter of type 'import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/core").default'.
Types of property 'opts' are incompatible.
Type 'import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/core").InstanceOptions' is not assignable to type 'import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/core").InstanceOptions'.
Type 'InstanceOptions' is not assignable to type 'CurrentOptions'.
Types of property 'keywords' are incompatible.
Type 'import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/types/index").Vocabulary | undefined' is not assignable to type 'import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/types/index").Vocabulary | undefined'.
Type 'Vocabulary' is not assignable to type '(string | KeywordDefinition)[]'.
Type 'string | import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/types/index").KeywordDefinition' is not assignable to type 'string | import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/types/index").KeywordDefinition'.
Type 'CodeKeywordDefinition' is not assignable to type 'string | KeywordDefinition'.
Type 'import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/types/index").CodeKeywordDefinition' is not assignable to type 'import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/types/index").CodeKeywordDefinition'.
Types of property 'code' are incompatible.
Type '(cxt: import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/compile/validate/index").KeywordCxt, ruleType?: string | undefined) => void' is not assignable to type '(cxt: import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/index").KeywordCxt, ruleType?: string | undefined) => void'.
Types of parameters 'cxt' and 'cxt' are incompatible.
Type 'import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/compile/validate/index").KeywordCxt' is not assignable to type 'import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/compile/validate/index").KeywordCxt'.
The types of 'gen._scope' are incompatible between these types.
Type 'import("c:/Users/dev-user/Projects/mono-crm/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/scope").Scope' is not assignable to type 'import("c:/Users/dev-user/Projects/mono-crm/neo-api/node_modules/ajv/dist/compile/codegen/scope").Scope'.
Property '_names' is protected but type 'Scope' is not a class derived from 'Scope'.ts(2345)
```

Asking Chatgpt, it said that it is the version problem, so I installed v2 of `ajv-formats` like this:
```
npm i ajv-formats@^2
```
And it's fixed!

I think peer dependency to `ajv` in `package.json` must be fixed.
https://github.com/ajv-validator/ajv-formats/blob/4ca86d21bd07571a30178cbb3714133db6eada9a/package.json#L40-L42

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.