Can you provide some guidance on the best way to use JSDoc for generic TypeScript functions? I attempted to implement it as shown below, but received a prompt suggesting that
.JSDoc types may be moved to TypeScript types.ts(80004)
When I clicked on the "quick fix" option, it ended up causing issues with the function.
/**
* @description execute promises in parallel by chunks
* @type <ReturnType> : specifies the type of data to be returned
* @param arrayPromises : an array of promises to execute
* @param chunks : the number of chunks
* @returns : an array of ReturnType
*/
const runPromisesInParallelbyChunks = async <ReturnType>(
arrayPromises: Array<() => Promise<ReturnType>>,
chunks: number
): Promise<ReturnType[]> => {
const result: ReturnType[] = [];
let resu: ReturnType[] = [];
let cnt: number = 0;
const chain = async (
shrinkArray: Array<() => Promise<ReturnType>>
): Promise<ReturnType> => {
if (!shrinkArray.length) {
return new Promise<ReturnType>(resolve => resolve());
}
// console.log(shrinkArray.length);
const i: number = cnt++;
const res: ReturnType = await shrinkArray.shift()!();
await delayExecution(100);
// SAVE RESULT OF THE EXECUTION OF THE FUNCTION
result[i] = res;
return chain(shrinkArray);
};
const arrChains: Array<Promise<ReturnType>> = [];
while (chunks-- > 0 && arrayPromises.length > 0) {
arrChains.push(chain(arrayPromises));
}
// RESULT IS AN ARRAY OF THE RESULT OF EACH PROMISE
resu = await Promise.all(arrChains).then(() => result);
return resu;
};