I want to convert a html string to a html element in deno with typescript. I found this function for it:
function createElementFromHTML(htmlString: string) {
var div = document.createElement('div');
div.innerHTML = htmlString.trim();
return div.firstChild;
}
When I run it with this command:
deno run --allow-net .\scripts\API\fetchUtils.ts
It tells me this:
Cannot find name 'document'. Do you need to change your target library? Try changing the
lib
compiler option to include 'dom'.ts(2584)
After a bit of searching I found out that I need to add this to my tsconfig:
{
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"lib": ["esnext", "DOM"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"pretty": true,
"resolveJsonModule": true,
"target": "esnext"
},
"include": [
"./**/*.ts"
]
}
I still get the same error, restarts etc. didn't help.
I don't know if it makes a difference but this is how my project is structured from the standpoint of where I start running the deno file from the console:
scripts
-API
-fetchUtils.ts
tsconfig.json