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

Using ajv-formats with deno fails #85

Open
iherman opened this issue Oct 10, 2023 · 5 comments
Open

Using ajv-formats with deno fails #85

iherman opened this issue Oct 10, 2023 · 5 comments

Comments

@iherman
Copy link

iherman commented Oct 10, 2023

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
Copy link

zdila commented Mar 19, 2024

You can try

import addFormats from "https://esm.sh/[email protected]";

@silverwind
Copy link

silverwind commented May 17, 2024

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
Copy link

mosoriorian commented Jul 22, 2024

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

@leppaott
Copy link

leppaott commented Aug 1, 2024

Needs to fix the export ajv like ajv-validator/ajv#2381 ajv-validator/ajv-keywords#388 etc
Workaround for now: microsoft/TypeScript#50058 (comment)

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

@fuji44
Copy link

fuji44 commented Sep 26, 2024

Although this is a tentative response, it can be avoided by either (deno 1.46.3)

import { Ajv, type Plugin } from "npm:[email protected]";
import ajvFormats, { type FormatsPluginOptions } from "npm:[email protected]";
const addFormats = ajvFormats as unknown as Plugin<FormatsPluginOptions>;
// The version of ajv must match the dependency on [email protected].
import Ajv from "https://esm.sh/[email protected]";
import addFormats from "https://esm.sh/[email protected]";

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

No branches or pull requests

6 participants