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

Export Execa and ExecaScript types. #1062

Closed
Shakeskeyboarde opened this issue May 16, 2024 · 2 comments · Fixed by #1066
Closed

Export Execa and ExecaScript types. #1062

Shakeskeyboarde opened this issue May 16, 2024 · 2 comments · Fixed by #1066

Comments

@Shakeskeyboarde
Copy link

The "currying" capability built-in to execa() and $ are nice, but I would like to be able to correctly type curried return values.

For example...

const executeSomething = async (exec: typeof execa = execa): Promise<void> => {
  // ...
});

// type error
await executeSomething(execa({ encoding: 'buffer' }));

The type error is...

Argument of type 'Execa<{ encoding: "buffer"; }>' is not assignable to parameter of type 'Execa<{}>'.
  Type 'ResultPromise<{ encoding: "buffer"; }>' is not assignable to type 'ResultPromise<{}>'.
    Type 'ResultPromise<{ encoding: "buffer"; }>' is not assignable to type '{ pid?: number | undefined; send: undefined; stdin: Writable; stdout: Readable; stderr: Readable; all: undefined; stdio: SubprocessStdioArray<{}>; ... 5 more ...; [Symbol.asyncIterator](): SubprocessAsyncIterable<...>; }'.
      The types returned by '[Symbol.asyncIterator]()' are incompatible between these types.
        Type 'SubprocessAsyncIterable<undefined, "buffer">' is not assignable to type 'SubprocessAsyncIterable<undefined, unknown>'.
          Type 'Uint8Array' is not assignable to type 'string'. ts(2345)

Instead of using typeof execa, it would be great to use Execa<Options & { encoding: "buffer" }> (or similar), but that's not possible because the Execa type is not exported. And the same goes for ExecaScript.

@ehmicky
Copy link
Collaborator

ehmicky commented May 17, 2024

Hi @Shakeskeyboarde,

Great point. I have created a PR at #1066 to add those new types.

@ehmicky
Copy link
Collaborator

ehmicky commented Jun 6, 2024

This was released in 9.2.0.

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

Successfully merging a pull request may close this issue.

2 participants