-
Couldn't load subscription status.
- Fork 24
Add TS typings #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TS typings #10
Conversation
|
@yenbekbay It might be wise to hold off on merging typings that require 2.8+ at this point. I think a lot of people are still on 2.7, myself included (2.8 is broken on my projects). I wonder - do you think it'd be worth doing a PR without the conditional types in the interim? FWIW I've picked up TypeScript now and would be happy to hack on porting this library over to be written in TS if that's interesting to you. |
|
Maybe you can first publish a |
|
@fimars When will you accept whit PR? Very useful |
|
@nemmo I am not maintaining this project. This PR is as @developit said, some of the broken changes may not be merged now. Maybe you can make a new PR. 🤔 |
|
There is no any broken changes cause it is just typing definitions that allows to use that library in TypeScript projects. |
@nemmo author said. |
| */ | ||
| parallel<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>( | ||
| list: [ | ||
| AsyncFn<T1>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to avoid having to cap the list here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, yes, but only if we use rest parameters instead of a single list parameter.
With the introduction of rest parameters with tuple types in TypeScript 3.0 and mapped types on tuples in TypeScript 3.1, we can simplify the type definition for the parallel method to this:
series<T extends any[]>(
...list: T
): Promise<{[K in keyof T]: AsyncFnReturnType<T[K]>}>;But then, it's probably not an option to change the function signature.
However, with the introduction of optional elements in tuple types in TypeScript 3.0, we can get rid of overloads and reduce the method's type definition to:
series<
T extends [any, any?, any?, any?, any?, any?, any?, any?, any?, any?]
>(
list: T,
): Promise<{[K in keyof T]: AsyncFnReturnType<T[K]>}>;Then, we can increase the capping to a higher number of elements (by adding extra any? elements to the generic tuple type) without adding a ton of overloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@developit @yenbekbay any chance to get a new version with the updated typings? This is really a blocker for those who use Typescript :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript is version 3.7 now. Maybe we can do something.
cc @developit
Note: these typings will only work with TS 2.8+, as they make use of Conditional types to infer the return types of async functions.