вначале код был написан на JS, сейчас переписываю на TS.
имеется базовый класс:
import { Dom } from './dom';
import { capitalize } from './utils';
export class DomListener {
private $root: Dom;
private listeners: string[];
constructor($root: Dom, listeners: string[] = []) {
if (!$root) {
throw new Error('No $root provided for DomListener');
}
this.$root = $root;
this.listeners = listeners;
}
initDomListener() {
console.log(this);
this.listeners.forEach((listener) => {
const method = getMethodName(listener);
if (!this[method]) {
throw new Error(`Method ${method} is not implemented in ${name} Component`);
}
this[method] = this[method].bind(this);
this.$root.on(listener, this[method]);
});
}
}
function getMethodName(eventName: string) {
return 'on' + capitalize(eventName);
}
с которого наследуется промежуточный и далее класс конечного элемента.
в промежуточном классе вызывается init который в свою очередь из основного вызывает initDomListener, суть всего действия перебиндить методы с конечного элемента в контекст базового класса.
и установить "прослушивателей" событий.
сам код работает, но TS даёт предупреждения на this[method]:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'DomListener'.
No index signature with a parameter of type 'string' was found on type 'DomListener'.
помогите правильно избавить от них.
спасибо!!!