I've been grappling with getting xmllint to function correctly within Typescript.
Given that it's written in traditional JS, attempting to import the module directly into Typescript results in a compile error:
Cannot find module 'xmllint' or its corresponding type declarations.
To resolve this issue, I created an index.d.ts
file in my root directory :
declare module 'xmllint'{
export interface ValidationResult{
errors: string[]
};
export interface Options{
xml: string, xsd:string
}
export function validateXML(opts: Options): ValidationResult;
}
Although this now compiles without errors, I'm unable to successfully import the module into a Typescript class. It consistently either returns an empty object or undefined
.
I have attempted:
, resulting in an empty object for validateXMLimport {validateXML} from "xmllint"
, causing validateXML to be undefinedimport validateXML from "xmllint"
, leading to validateXML being an empty objectimport * as validate from "xmllint"
Shown below is my tsconfig.json
{
"compilerOptions": {
"target": "es2016",
"module": "esnext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
}
It seems like the issue lies in my index.d.ts
not properly referring to the native xmllint function, but I'm unsure of how to address this.
What am I overlooking?