Skip to content

Commit c13b4ef

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

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ 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+
expectType<Promise<[PromiseResult<number>, PromiseResult<string>]>>(pSettle([1, '2']));
11+
expectType<Promise<[PromiseResult<string>, PromiseResult<number>]>>(pSettle([Promise.resolve('1'), Promise.resolve(2)]));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@
5151
"in-range": "^2.0.0",
5252
"time-span": "^3.1.0",
5353
"tsd": "^0.11.0",
54-
"xo": "^0.27.2"
54+
"xo": "^0.30.0"
5555
}
5656
}

0 commit comments

Comments
 (0)