我将以下TypeScript程序转换为ES5:
档案1:
class BaseElement extends HTMLElement {
constructor() {
super();
}
}
Run Code Online (Sandbox Code Playgroud)
文件2:
import {BaseElement} from './BaseElement';
class MyElement extends BaseElement {
constructor() {
super();
}
}
var el = new MyElement();
Run Code Online (Sandbox Code Playgroud)
将所有内容手动放入文件中,代码工作正常并在浏览器中执行,HTMLElement构造没有问题.但是,只要我通过webpack打包它,我收到以下错误消息:
Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
Run Code Online (Sandbox Code Playgroud)
没有webpack,构造了以下JS代码:
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor …Run Code Online (Sandbox Code Playgroud)