I'm trying to type an array that contains objects which contain arrays of functions. TypeScript is giving the error: TS2339: Property 'push' does not exist on type '{ name?: (() => void)[]; }'.
The _observerCallbacks object should look like:
{
main: [function1..., function2...],
second: [function1..., function2...]
}
This is what my code looks like.
export class LoadingTracker {
private _observerCallbacks: { name?: { (): void; }[] }[] = [];
registerObserverCallback(callback, name): void {
if (typeof this._observerCallbacks[name] === 'undefined') this._observerCallbacks[name] = [];
this._observerCallbacks[name].push(callback);
}
notifyObservers(): void {
this._observerCallbacks.forEach((callback: { (): void; }): void => {
callback();
});
}
}
I can't figure out where I'm going wrong.