Answer the question
In order to leave comments, you need to log in
Typescript. How to type this?
Hello.
I have:
this.listeners.forEach((listener) => {
const method: string = getMethodName(listener);
if (method in this) {
this[method] = this[method].bind(this);
this.$root.addEventListener(listener, this[method]);
}
});
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Listener'. No index signature with a parameter of type 'string' was found on type 'Listener'.
Answer the question
In order to leave comments, you need to log in
What, sorry?
Doesn't bother you, does it? You already have a scope - .
this[method] = this[method].bind(this);
this.$root.addEventListener(listener, () => this[method]());
this[method]
if it doesn't work. public void on(string event, ((Event event) => void) callback)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question