ajv-formats icon indicating copy to clipboard operation
ajv-formats copied to clipboard

Type Error using ajv-formats with ajv v8.11.0

Open tnguye72 opened this issue 2 years ago • 1 comments

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?

tnguye72 avatar May 09 '22 21:05 tnguye72

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.

rygo11 avatar May 30 '22 23:05 rygo11