I have the following TypeScript code:
let script: HTMLElement = document.createElement("script");
script.appendChild(document.createTextNode(`
{
"json": "property"
}
`));
script.id = 'appContextModel';
document.body.appendChild(script);
And I'm getting the following error:
Uncaught SyntaxError: Unexpected token :
I think because the script variable does not have the property type with value application/json when I try to append to the body that HTMLElement, the compiler is retrieving the error.
What I'm looking for is a way to add the type="application/json" property to the script element, using only TypeScript.