How to fix Typescript HTMLElement constructor: 'new' is required

Viewed 22

I'm making loop custom element with TS.
As I make Loop class, it compile to function and caught error at the _super.call(this) inside of var Loop

My Typescript file

class Loop extends HTMLElement {
  constructor() {
    super();
    const a = document.createElement('div');
    a.innerText = 'a';
    this.appendChild(a);
  }
}

customElements.define('loop-', Loop);

Outfile

var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var Loop = /** @class */ (function (_super) {
    __extends(Loop, _super);
    function Loop() {
        var _this = _super.call(this) || this;
        var a = document.createElement('div');
        a.innerText = 'a';
        _this.appendChild(a);
        return _this;
    }
    return Loop;
}(HTMLElement));
customElements.define('loop-', Loop);

Error

Uncaught TypeError: HTMLElement constructor: 'new' is required
0 Answers
Related