I'm encountering some difficulties with strong typing in relation to this._onResize
and onMouseDown
.
At line 28, the error
ESLint: Unsafe call of an any typed value.(@typescript-eslint/no-unsafe-call)
is thrown when onMouseDown(event, this);
is called.
Lines 37-38 throw the error
S2769: No overload matches this call.
when this._handle.removeEventListener('mousedown', this._onResize);
and this._handle.removeEventListener('touchstart', this._onResize);
are used.
The detailed explanation states:
TS2769: No overload matches this call. Overload 1 of 2, '(type: keyof ElementEventMap, listener: (this: Element, ev: Event) => any, options?: boolean | EventListenerOptions | undefined): void', resulted in the following error. Argument of type '"mousedown"' is not assignable to parameter of type 'keyof ElementEventMap'. Overload 2 of 2, '(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void', led to the following error. Argument of type '((event: MouseEvent | TouchEvent) => void) | null | undefined' is not assignable to parameter of type 'EventListenerOrEventListenerObject'. Type 'undefined' is not assignable to type 'EventListenerOrEventListenerObject'.
The relevant code snippet is shown below:
import { Renderer2 } from '@angular/core';
export class ResizeHandle {
protected _handle: Element | undefined | null;
private _onResize: ((event: MouseEvent | TouchEvent) => void) | undefined | null;
constructor(
protected parent: Element,
protected renderer: Renderer2,
public type: string,
public css: string,
private onMouseDown
) {
// implementation details omitted for brevity...
}
dispose(): void {
if (this._handle) {
this._handle.removeEventListener('mousedown', this._onResize);
this._handle.removeEventListener('touchstart', this._onResize);
if (this.parent) {
this.parent.removeChild(this._handle);
}
}
this._handle = null;
this._onResize = null;
}
get element(): Element | undefined | null {
return this._handle;
}
}
What specific types should be assigned to these variables?