Compile typescript

After I compiled type typescript to javascript, and added the javascript file to html file, on the Chrome, I encounter the following error:

After I compiled type typescript to javascript, and added the javascript file to html file, on the Chrome, I encounter the following error:

event.js:19 Uncaught TypeError: Failed to construct ‘HTMLElement’: Please use the ‘new’ operator, this DOM object constructor cannot be called as a function.
at new MenuItem (event.js:19)
at event.js:62

After I search the internet, and find some solutions from [Bug] angular/elements: Failed to construct ‘HTMLElement’: Please use the ‘new’ operator #24556

Solution 1

Compile typescript with the following command, specify es2015 as the target, and the javascript can run on Chrome now.

tsc -t es2015 event.ts

Install tsc command:

npm install -g typescript

Solution 2

Add the following javascript to the html file:

<script src=”https://unpkg.com/@webcomponents/webcomponentsjs@2.0.3/custom-elements-es5-adapter.js"></script>