execa
execa copied to clipboard
Export `Execa` and `ExecaScript` types.
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.
Hi @Shakeskeyboarde,
Great point. I have created a PR at #1066 to add those new types.
This was released in 9.2.0.