Answer the question
In order to leave comments, you need to log in
What is the best way to make a type for a callback with this passing to it?
Tell me the type for the callback, so that there would be a highlight of the methods
class BaseLol {
myMethod1(arg = 123) {
return arg;
}
public extend(callback: CallableFunction) {
callback(this);
return this;
}
/* ... */
}
class Lol extends BaseLol {
myMethod2(arg = "qwe") {
return arg;
}
}
const instance = new Lol();
instance.extend((inst) => { //<<< нужен тип что бы узнать какие пропсы, методы и тд...
inst.customProp = 'lol';
inst.myMethod1(123123);
});
Answer the question
In order to leave comments, you need to log in
public extend(callback: (inst: this) => void) {
callback(this);
return this;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question