Syntax for Ajv import?
See original GitHub issueWhat version of Ajv are you using? Does the issue happen if you use the latest version?
Version 8.11.0, installed today
Ajv options object None.
Your code
// ProjectJSON.mts
// this works, https://github.com/microsoft/TypeScript/issues/24847}
import { default as Ajv } from "ajv";
// this doesn't work, but is the currently recommended import line
//import Ajv from "ajv";
/*
_02_passthrough_types/source/ProjectJSON.mts(98,17): error TS2351: This expression is not constructable.
Type 'typeof import("/home/ajvincent/code-generation/cross-stitch/node_modules/ajv/dist/ajv")' has no construct signatures.
*/
const ajv = new Ajv();
void(ajv);
I was bitten on this exact error with https://github.com/dsherret/code-block-writer/issues/42 a few weeks ago.
Are you going to resolve the issue?
I can, by adding a little bit of documentation. I just need to know where people want it, if they don’t want to quickly fix this themselves.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Getting started - Ajv JSON schema validator
Ajv takes a schema for your JSON data and converts it into a very efficient JavaScript code that validates your data according to...
Read more >User defined keywords - Ajv JSON schema validator
import {_, KeywordCxt} from Ajv ajv.addKeyword({ keyword: "even", type: "number", schemaType: "boolean", // $data: true // to support [$data reference](.
Read more >API Reference | Ajv JSON schema validator
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Read more >ajv-cli
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Read more >Ajv JSON schema validator
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm that the normal import doesn’t work when using
moduleResolution
node16
ornodenext
. We are currently using the following workaround:The above was needed whenever your project was targeting ESM output from typescript. i.e. moduleResolution = NodeNext/Node16+ and module = NodeNext/Node16+.
With typescript 4.8.3 the above actually stopped working and started producing a different type error for me. I stumbled across this comment on a typescript issue. It seems typescript is pointing blame on the libraries being incorrectly typed for whatever reason.
To fix my error I had to switch back to
and then when I go and try to use the Ajv class it is actually something like