Skip to content
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

Variadic types #12

Closed
ValentinH opened this issue May 7, 2020 · 3 comments · Fixed by #13
Closed

Variadic types #12

ValentinH opened this issue May 7, 2020 · 3 comments · Fixed by #13

Comments

@ValentinH
Copy link
Contributor

Today, the TS definition does not support having different type for each promise passed.

This is a known limitation in Typescript and there is a funny workaround that can be seen in the definition for Promise.all(): https://github.com/microsoft/TypeScript/blob/master/lib/lib.es2015.promise.d.ts#L113

Would you accept a PR that would apply the same pattern in the d.ts file?

@sindresorhus
Copy link
Owner

Sure

@ValentinH
Copy link
Contributor Author

While doing it I actually faced a bug also present in Promise.all(): microsoft/TypeScript#33752

I'll see if the fix in the PR (https://github.com/microsoft/TypeScript/pull/33707/files) is also working for pSettle, if yes, I'll do the PR.

@ValentinH
Copy link
Contributor Author

It is working 🎉

type Awaited<T> = T extends undefined ? T : T extends PromiseLike<infer U> ? U : T
export function pSettle<T extends readonly any[]>(
  values: T,
  options?: pSettle.Options
): Promise<{ -readonly [P in keyof T]: PromiseResult<Awaited<T[P]>> }> // 

However, as the PR on TS is not fixed I don't know if this could lead to unexpected issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants