Skip to content

Commit 03dd315

Browse files
authored
types: add overload for static array in async.all func (#314)
1 parent f791dcf commit 03dd315

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "radash",
3-
"version": "10.9.0",
3+
"version": "11.0.0",
44
"description": "Functional utility library - modern, simple, typed, powerful",
55
"main": "dist/cjs/index.cjs",
66
"module": "dist/esm/index.mjs",

src/async.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ type PromiseValues<T extends Promise<any>[]> = {
162162
* slack.customerSuccessChannel.sendMessage(...)
163163
* ])
164164
*/
165+
export async function all<T extends [Promise<any>, ...Promise<any>[]]>(
166+
promises: T
167+
): Promise<PromiseValues<T>>
165168
export async function all<T extends Promise<any>[]>(
166169
promises: T
167170
): Promise<PromiseValues<T>>

src/tests/async.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -521,22 +521,22 @@ describe('async module', () => {
521521

522522
describe('_.all', () => {
523523
const promise = {
524-
pass: <T>(value: T) => new Promise<T>(res => res(value)),
525-
fail: (err: any) => new Promise((res, rej) => rej(err))
524+
resolve: <T>(value: T) => new Promise<T>(res => res(value)),
525+
reject: (err: any) => new Promise((res, rej) => rej(err))
526526
}
527527
it('returns array with values in correct order when given array', async () => {
528528
const result = await _.all([
529-
promise.pass(22),
530-
promise.pass('hello'),
531-
promise.pass({ name: 'ray' })
529+
promise.resolve(22),
530+
promise.resolve('hello'),
531+
promise.resolve({ name: 'ray' })
532532
])
533533
assert.deepEqual(result, [22, 'hello', { name: 'ray' }])
534534
})
535535
it('returns object with values in correct keys when given object', async () => {
536536
const result = await _.all({
537-
num: promise.pass(22),
538-
str: promise.pass('hello'),
539-
obj: promise.pass({ name: 'ray' })
537+
num: promise.resolve(22),
538+
str: promise.resolve('hello'),
539+
obj: promise.resolve({ name: 'ray' })
540540
})
541541
assert.deepEqual(result, {
542542
num: 22,
@@ -547,9 +547,9 @@ describe('async module', () => {
547547
it('throws aggregate error when a single promise fails (in object mode)', async () => {
548548
try {
549549
await _.all({
550-
num: promise.pass(22),
551-
str: promise.pass('hello'),
552-
err: promise.fail(new Error('broken'))
550+
num: promise.resolve(22),
551+
str: promise.resolve('hello'),
552+
err: promise.reject(new Error('broken'))
553553
})
554554
} catch (e: any) {
555555
const err = e as AggregateError
@@ -562,9 +562,9 @@ describe('async module', () => {
562562
it('throws aggregate error when a single promise fails (in array mode)', async () => {
563563
try {
564564
await _.all([
565-
promise.pass(22),
566-
promise.pass('hello'),
567-
promise.fail(new Error('broken'))
565+
promise.resolve(22),
566+
promise.resolve('hello'),
567+
promise.reject(new Error('broken'))
568568
])
569569
} catch (e: any) {
570570
const err = e as AggregateError

0 commit comments

Comments
 (0)