ajv-validator / ajv-formats

JSON Schema format validation for Ajv v8+
https://ajv.js.org
MIT License
186 stars 36 forks source link

Type Error using ajv-formats with ajv v8.11.0 #67

Open tnguye72 opened 2 years ago

tnguye72 commented 2 years ago

I have a typescript project and am following instructions to add "date-time" as follows:

let ajv = new Ajv({ allErrors: true});
addFormats(ajv, ["date-time"]);

but getting the following error for "ajv", the first argument to addFormats: Type 'Ajv' is missing the following properties from type 'Ajv': opts, logger, scope, schemas, and 17 more.

My tsconfig is as follows:

{
  "compilerOptions": {
    "module": "CommonJS",
    "target": "ES2020",
    "noImplicitAny": true,
    "preserveConstEnums": true,
    "outDir": "./build",
    "sourceMap": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "moduleResolution": "node"
  },
  "exclude": ["node_modules"],
  "include": ["my-project/src/**/*", "docs/**/*.json"]
}

The only way I was able to get it working was by initializing ajv as 'any' type, which doesn't seem ideal. Any ideas as to what could be the issue?

rygo11 commented 2 years ago

I had the same issue and fixed it by making sure I had the most up to date versions of both dependencies: "ajv": "^8.8", "ajv-formats": "^2.1.1",

I think another package must have installed an older version of ajv.