-
-
Notifications
You must be signed in to change notification settings - Fork 876
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
Syntax for Ajv import? #2047
Comments
difficult to say what is incorrect without seeing your TS configuration.
|
Here's what I have: {
"compilerOptions": {
"lib": ["es2022"],
"module": "es2022",
"target": "es2022",
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"experimentalDecorators": true
},
"exclude": [
"spec/**"
],
"extends": "@tsconfig/node16/tsconfig.json"
}
The file is https://github.com/ajvincent/cross-stitch/blob/main/_02_passthrough_types/source/ProjectJSON.mts |
This configuration works for me: {
"compilerOptions": {
"esModuleInterop": true,
"module": "node16",
"moduleResolution": "node",
"sourceMap": true,
"strict": true
}
} Maybe both |
import { default as Ajv } from 'ajv' 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 import Ajv from 'ajv' and then when I go and try to use the Ajv class it is actually something like const ajv = new Ajv.default() |
I can confirm that the normal import doesn't work when using import AjvModule from 'ajv'
// FIXME: https://github.com/ajv-validator/ajv/issues/2047
const Ajv = AjvModule.default |
This is solving an issue where it's impossible for me to import Ajv in a typescript project. This might solve ajv-validator#2047 and allows the use of import { Ajv } from 'ajv';
This is solving an issue where it's impossible for me to import Ajv in a typescript project. This solves ajv-validator#2047 for me import { Ajv } from 'ajv';
This is solving an issue where it's impossible for me to import Ajv in a typescript project. This solves ajv-validator#2047 for me import { Ajv } from 'ajv';
In TypeScript 5.0, you can set My {
"compilerOptions": {
/* Modules */
"module": "ES2022", /* Specify what module code is generated. */
"moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
...
}
} |
This is not a bug with the TypeScript compiler but a "feature"... See microsoft/TypeScript#49160 See ajv-validator/ajv#2047
Is this still an issue? |
@jasoniangreen No - it was fixed in #2389 |
What 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
I was bitten on this exact error with dsherret/code-block-writer#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.
The text was updated successfully, but these errors were encountered: