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
Update execa libdef #2585
Update execa libdef #2585
Conversation
This is wrong; execa does not return a real Promise; it just adds methods I disagree with this change, because it makes the definition incorrect. I recommend to fix execa to define all Promise's methods on the returned object, so we can treat it as a union of |
@jirutka I see, that makes sense. But this is still is a problem then: async () => {
const children: ThenableChildProcess[] = [1, 2, 3].map(x => execa(`echo ${x}`))
children.forEach(child => child.stdin.end('unicorns'))
const results = await Promise.all(children);
(results: Result[]) // INCORRECT FLOW ERROR
}; Do you have any ideas? Either we incorrectly mark I guess the best solution would be to ask @sindresorhus if he objects to making it a real promise somehow, or at least just adding a |
He says he's happy to add a |
Waiting on @jirutka, ping me when this is ready to move forward. |
I've submitted sindresorhus/execa#174 to make if fully compatible with Promise. The updated typedef should extend Promise instead of redefining Promise methods. Something like: declare interface ExecaPromise extends Promise<Result>, child_process$ChildProcess {
catch<E>(
onrejected?: ?((reason: ExecaError) => E | Promise<E>)
): Promise<Result | E>;
} |
Ping us when the PR is merged. :-) |
Closing in favour of a new PR. |
This updates the new execa libdef to make it compatible with
Promise.all()
.eef807d
) adds a failing test case.27a5373
) fixes it.The downside is you no longer automatically get the
ExecaError
type when you catch an error, so you have to explicitly type it like.catch((err: ExecaError) => ...
if you need the typing, or it will be typed asany
. But I think this is probably more correct anyway, as there's no hard guarantee that anything passed to an execa's.catch()
will always be the expected error type.Pinging @jirutka for comment.