Let's imagine two classes, A and B. Class A sets the parameters that can be used by class B. However, when it comes to callback functions, A doesn't know what type of parameter will be passed from B. Therefore, in class A, these parameters are simply defined as Objects.
class A {
private _on_user_selection:(selection:Object) => void = $.noop;
set on_user_selection(fn:(selection:Object) => void) {
if ($.isFunction(fn)) {
this._on_user_selection = fn;
}
}
}
class B extends A {
// ...
}
Class B, on the other hand, knows exactly what type of parameter to expect in its callback function. So, how can we ensure that we can use it like this:
let b = new B();
b.on_user_selection = (selection:SomeInterfaceDefindeSomewhere):void => {
// ...
};
In this scenario, the code provided above would work perfectly fine. However, the goal is to update the return type of the callback function within class B itself, not just where it's called.