const sequence = ( promises: Array<() => Promise> ): Promise> => { return new Promise((resolve, reject) => { const output: Array = []; const next = (index: number): void => { if (index < promises.length) { promises[index]() .then((result) => { output[index] = result; }) .then(() => { next(index + 1); }) .catch(reject); } else { resolve(output); } }; next(0); }); }; export default sequence;