Typescript Нет перегрузки соответствует этому событию onmouseover вызова - PullRequest
0 голосов
/ 17 марта 2020

Я довольно новичок ie для Typescript. Я получаю ошибку перегрузки при попытке назначить прослушиватель события onmouseover в машинописи. Я почти уверен, что это ошибка ладьи. Буду признателен за помощь.

Вот мой код:

Пользовательский класс SVG:

class CustomSVGElement {
    type: string;
    namespace: string;
    node: Element;
    constructor(type: string) {
        this.type = type;
        this.namespace = 'http://www.w3.org/2000/svg';
        this.node = document.createElementNS(this.namespace, this.type);
        return this;
    }


    attr(attrs: object) {
        for (const [key, value] of Object.entries(attrs)) {
            this.node.setAttributeNS(null, key, value);
        }
        return this;
    }

    append(element: any) {
        const parent = (typeof element === 'string') ? document.querySelector(element) : element.node;
        parent.appendChild(this.node);
        return this;
    }

    addInnerHTML(innerHTML: string) {
        if (innerHTML != undefined) {
            this.node.innerHTML = innerHTML;
        }
        return this;
    }
}

class Sight {
  svg: any;
  constructor(selector: string, width: number, height: number) {
    this.svg = new CustomSVGElement(selector).attr({ width: `${width}`, height: `${height}`}).append(selector);
  }

  draw(type: string, attrs: object, innerHTML: string) {
    return new CustomSVGElement(type).attr(attrs).addInnerHTML(innerHTML).append(this.svg);
  }
}

Метод основного класса:

const svg: Sight = new Sight('.svg', 1500, 600);
const svgPath = svg.draw('path', {class: "baseCategory", d: <some svg path value>}, undefined);
const onMouseOver = (e: MouseEvent) => console.log(`(${e.x}, ${e.y})`);
svgPath.node.addEventListener("mouseover", onMouseOver);

При выполнении выше, компилятор машинописи начинает выдавать мне эту ошибку:

No overload matches this call.
  Overload 1 of 2, '(type: "fullscreenchange" | "fullscreenerror", listener: (this: Element, ev: Event) => any, options?: boolean | AddEventListenerOptions): void', gave the following error.
    Argument of type '"mouseover"' is not assignable to parameter of type '"fullscreenchange" | "fullscreenerror"'.
  Overload 2 of 2, '(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void', gave the following error.
    Argument of type '(e: MouseEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
      Type '(e: MouseEvent) => void' is not assignable to type 'EventListener'.
        Types of parameters 'e' and 'evt' are incompatible.
          Type 'Event' is missing the following properties from type 'MouseEvent': altKey, button, buttons, clientX, and 20 more.ts(2769)
...