Skip to content

Commit af7a91a

Browse files
author
Valentin Hervieu
committed
Improve Typescript definition: support variadic type arrays
1 parent d622e91 commit af7a91a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

index.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ declare namespace pSettle {
1717
type PromiseResult<ValueType> = pReflect.PromiseResult<ValueType>;
1818
type PromiseFulfilledResult<ValueType> = pReflect.PromiseFulfilledResult<ValueType>;
1919
type PromiseRejectedResult = pReflect.PromiseRejectedResult;
20+
21+
type Awaited<T> = T extends undefined ? T : T extends PromiseLike<infer U> ? U : T
2022
}
2123

2224
/**
@@ -52,9 +54,9 @@ import pSettle = require('p-settle');
5254
})();
5355
```
5456
*/
55-
declare function pSettle<ValueType>(
56-
array: ReadonlyArray<ValueType | PromiseLike<ValueType> | ((...args: any[]) => PromiseLike<ValueType>)>,
57+
declare function pSettle<ValueType extends readonly any[]>(
58+
array: ValueType,
5759
options?: pSettle.Options
58-
): Promise<Array<pSettle.PromiseResult<ValueType>>>;
60+
): Promise<{ -readonly [P in keyof ValueType]: pSettle.PromiseResult<pSettle.Awaited<ValueType[P]>> }>
5961

6062
export = pSettle;

index.test-d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ expectType<Promise<Array<PromiseResult<number>>>>(pSettle([1, Promise.resolve(2)
66
expectType<Promise<Array<PromiseResult<number>>>>(
77
pSettle([1, Promise.resolve(2)], {concurrency: 1})
88
);
9+
10+
11+
expectType<Promise<[PromiseResult<number>, PromiseResult<string>]>>(pSettle([1, '2']));
12+
expectType<Promise<[PromiseResult<string>, PromiseResult<number>]>>(pSettle([Promise.resolve('1'),Promise.resolve(2)]));

0 commit comments

Comments
 (0)