Pass the array to eachSeries asynchronous library - expects a Dictionary <{}> '

I have the following TypeScript code:

const allDescribeBlocks: Array<ITestSuite> = suman.allDescribeBlocks;

async.eachSeries(allDescribeBlocks, function (block: ITestSuite, cb: Function) {

//....

}, cb);

this will be forwarded with warnings:

An argument of type ITestSuite [] is not assigned to a parameter of type Dictionary <{}>. ITestSuite [] does not have an index signature.

How to fix?

Here is the exact warning: enter image description here

+6
source share
1 answer

Have you installed the latest type definition for an asynchronous library?

npm install --save @types/async

I just checked their source and it should accept both an array and a collection:

export function each<T, E>(arr: T[] | IterableIterator<T>, iterator: AsyncIterator<T, E>, callback?: ErrorCallback<E>): void;
export function each<T, E>(arr: Dictionary<T>, iterator: AsyncIterator<T, E>, callback?: ErrorCallback<E>): void;
export const eachSeries: typeof each;

, tsconfig.json "typeRoots": ["node_modules/@types"], .

. , Array<T> T[].

+2

All Articles