Skip to content

Commit

Permalink
types: add overload for static array in async.all func (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
sodiray authored Jun 27, 2023
1 parent f791dcf commit 03dd315
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radash",
"version": "10.9.0",
"version": "11.0.0",
"description": "Functional utility library - modern, simple, typed, powerful",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
3 changes: 3 additions & 0 deletions src/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ type PromiseValues<T extends Promise<any>[]> = {
* slack.customerSuccessChannel.sendMessage(...)
* ])
*/
export async function all<T extends [Promise<any>, ...Promise<any>[]]>(
promises: T
): Promise<PromiseValues<T>>
export async function all<T extends Promise<any>[]>(
promises: T
): Promise<PromiseValues<T>>
Expand Down
28 changes: 14 additions & 14 deletions src/tests/async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,22 +521,22 @@ describe('async module', () => {

describe('_.all', () => {
const promise = {
pass: <T>(value: T) => new Promise<T>(res => res(value)),
fail: (err: any) => new Promise((res, rej) => rej(err))
resolve: <T>(value: T) => new Promise<T>(res => res(value)),
reject: (err: any) => new Promise((res, rej) => rej(err))
}
it('returns array with values in correct order when given array', async () => {
const result = await _.all([
promise.pass(22),
promise.pass('hello'),
promise.pass({ name: 'ray' })
promise.resolve(22),
promise.resolve('hello'),
promise.resolve({ name: 'ray' })
])
assert.deepEqual(result, [22, 'hello', { name: 'ray' }])
})
it('returns object with values in correct keys when given object', async () => {
const result = await _.all({
num: promise.pass(22),
str: promise.pass('hello'),
obj: promise.pass({ name: 'ray' })
num: promise.resolve(22),
str: promise.resolve('hello'),
obj: promise.resolve({ name: 'ray' })
})
assert.deepEqual(result, {
num: 22,
Expand All @@ -547,9 +547,9 @@ describe('async module', () => {
it('throws aggregate error when a single promise fails (in object mode)', async () => {
try {
await _.all({
num: promise.pass(22),
str: promise.pass('hello'),
err: promise.fail(new Error('broken'))
num: promise.resolve(22),
str: promise.resolve('hello'),
err: promise.reject(new Error('broken'))
})
} catch (e: any) {
const err = e as AggregateError
Expand All @@ -562,9 +562,9 @@ describe('async module', () => {
it('throws aggregate error when a single promise fails (in array mode)', async () => {
try {
await _.all([
promise.pass(22),
promise.pass('hello'),
promise.fail(new Error('broken'))
promise.resolve(22),
promise.resolve('hello'),
promise.reject(new Error('broken'))
])
} catch (e: any) {
const err = e as AggregateError
Expand Down

1 comment on commit 03dd315

@vercel
Copy link

@vercel vercel bot commented on 03dd315 Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.