I'm using lodash with TypeScript 1.8. At one point in the code I want to reduce from an array like this:
export interface IPackage {
[...]
dependencies?: IPackageReference[];
[...]
}
[...]
// pkg implements IPackageReference
lodash.reduce<IPackageReference, boolean>(pkg.dependencies, function(ref: IPackageReference, state: boolean) {
retu true;
}, true);
However, the compiler exits with a type mismatch:
package.ts(43,39): error TS2345: Argument of type 'IPackageReference[]' is not assignable to parameter of type 'Dictionary<IPackageReference>'.
Index signature is missing in type 'IPackageReference[]'.
The typings I use however should support Arrays however:
/**
* @see _.reduce
**/
reduce<T, TResult>(
collection: Array<T>,
callback: MemoIterator<T, TResult>,
thisArg?: any): TResult;
/**
* @see _.reduce
**/
reduce<T, TResult>(
collection: List<T>,
callback: MemoIterator<T, TResult>,
thisArg?: any): TResult;
/**
* @see _.reduce
**/
reduce<T, TResult>(
collection: Dictionary<T>,
callback: MemoIterator<T, TResult>,
thisArg?: any): TResult;
How do I get TSC to recognize my parameter as Array?
