Currently, I am encountering an issue while trying to use AJV with Typescript. I previously raised a similar concern in the ajv repository but unfortunately did not find a solution.
The problem arises when attempting to import the Ajv module as follows:
import Ajv from "ajv;
I aim to utilize it in the same manner as I would in plain JavaScript.
const ajv = new Ajv({ allErrors: true });
However, the TypeScript compiler is flagging an error like this:
error TS2351: This expression is not constructable.
Type 'typeof import("/Users/username/Documents/node_modules/ajv/dist/ajv")' has no construct signatures.
const ajv = new Ajv({ allErrors: true });
Could it be that I am making a mistake during the import procedure?
This is what my TS configuration file looks like:
`{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
/* Language and Environment */
"target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
/* Modules */
"module": "Node16", /* Specify what module code is generated. */
"moduleResolution": "Node16", /* Specify how TypeScript looks up a file from a given module specifier. */
/* JavaScript Support */
/* Emit */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
/* Interop Constraints */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"sourceMap": true,
"rootDir": "src",
"declaration": true,
"types": ["node", "mocha"]
},
"include": ["src/**/*", ".env"],
"exclude": ["dist/**/*", "node_modules", "test/**/*"]
}
`
Your assistance on this matter would be highly appreciated. Thank you very much....
I was under the impression that there should be no errors from the TS compiler since I compile JS files during the deployment process.