ajv-validator / ajv-formats

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

Using ajv-formats with deno fails #85

Open iherman opened 11 months ago

iherman commented 11 months ago

Using ajv-formats with TypeScript+deno (version 1.37.1) fails. I use the 'usual' idiom:

import addFormats from 'npm:ajv-formats':
.
.
.
addFormat(ajv);

and the compiler complains saying "This expression is not callable, [...]import [...] has no call signatures".

The same construction works with node.js+tsc.

I also looked at the index.d.ts file, as cached on my machine by deno, and it does not include any reference to addFormat at all, although the index.js file has it, but is not part of the exported formatsPlugin object.

Is this a deno bug or a bug with the distribution of ajv-formats?

zdila commented 5 months ago

You can try

import addFormats from "https://esm.sh/ajv-formats@2.1.1";
silverwind commented 3 months ago

Got the same issue with v3.0.1 with vite/node using typescript 5.4.5, the type definition resolves to this which has no call signature:

export interface FormatsPlugin extends Plugin<FormatsPluginOptions> {
    get: (format: FormatName, mode?: FormatMode) => Format;
}
mosoriorian commented 1 month ago

Any resolution on this? I have the same problem in Node 20 with Typesript 5.5.3 and moduleResolution: node16.

leppaott commented 1 month ago

Needs to fix the export ajv like https://github.com/ajv-validator/ajv/issues/2381 https://github.com/ajv-validator/ajv-keywords/issues/388 etc Workaround for now: https://github.com/microsoft/TypeScript/issues/50058#issuecomment-1297806160

import _addFormats from 'ajv-formats';
const addFormats = _addFormats as unknown as typeof _addFormats.default;