diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ae7f96..704b111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # deverything +## 1.8.1 + +### Patch Changes + +- seriesAll support tuple type + ## 1.8.0 ### Minor Changes diff --git a/package.json b/package.json index a4daea5..2b8a77a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deverything", - "version": "1.8.0", + "version": "1.8.1", "description": "Everything you need for Dev", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/helpers/seriesAll.ts b/src/helpers/seriesAll.ts index bbf2fe1..c3ab09c 100644 --- a/src/helpers/seriesAll.ts +++ b/src/helpers/seriesAll.ts @@ -1,4 +1,12 @@ -import { isFunction, isPromise } from "../validators"; +import { isFunction, isPromise } from '../validators' + +type SeriesResult = { + [K in keyof T]: T[K] extends Promise + ? U + : T[K] extends () => Promise + ? U + : never +} /** * @@ -11,20 +19,16 @@ import { isFunction, isPromise } from "../validators"; * async () => 4, * ]); => [1, 2, 3, 4] */ -export const seriesAll = async ( - series: (Promise | (() => Promise))[] -): Promise => { - const results = []; +export const seriesAll = async ( + series: readonly [...T], +): Promise> => { + const results: unknown[] = [] for (const fn of series) { - if (isPromise(fn)) results.push(await fn); - else if (isFunction(fn)) results.push(await fn()); - else throw new Error("seriesAll: invalid type"); + if (isPromise(fn)) results.push(await fn) + else if (isFunction(fn)) results.push(await fn()) + else throw new Error('seriesAll: invalid type') } - - // TODO: "as T[];" fix TS error - // error TS2345: Argument of type '(() => Promise) | Awaited' is not assignable to parameter of type 'T'. - // 'T' could be instantiated with an arbitrary type which could be unrelated to '(() => Promise) | Awaited'. - return results as T[]; -}; + return results as SeriesResult +} // TODO: rename to seriesAsync