While trying to assing a named object to an empty array of IBindings interface it gives this error, but it compiles fine and works fine.
Node 10.16.0, typescript 3.5.1, VSCode. Already Tried to change to extends to Array but doesn't work.
import { IBindings } from './ioc.interface';
export class ioc {
private _bindings: IBindings[];
constructor () {
this._bindings = [];
}
bind (namespace: string, closure: Function) {
if (typeof (closure) !== 'function') {
throw Error('IoC.bind expects second parameter to be a closure: ' + closure);
}
console.log(closure);
// Error is Right here
this._bindings[namespace] = {
closure: closure,
singleton: false,
cachedValue: null
}
console.log(`Binding ${namespace} to ioc container`);
}
}
export interface IBindings {
[namespace: string]: {
closure: Function,
singleton: boolean,
cachedValue: Function | null
}
}
I expect to not give any errors, because it is clearly a string that needs to be passed to IBindings, but the output is Element implicitly has an 'any' type because index expression is not of type 'number'.