Check out my TypeScript code snippet below:
let script: HTMLElement = document.createElement("script");
script.appendChild(document.createTextNode(`
{
"json": "property"
}
`));
script.id = 'appContextModel';
document.body.appendChild(script);
But I encountered a specific error:
Uncaught SyntaxError: Unexpected token :
I suspect this error is caused by the missing type
property with the value of application/json
in the HTMLElement
variable. This issue arises when trying to append it to the body.
My goal is to find a way to incorporate the type="application/json"
property into the script element using only TypeScript.