execa icon indicating copy to clipboard operation
execa copied to clipboard

Export `Execa` and `ExecaScript` types.

Open Shakeskeyboarde opened this issue 1 year ago • 1 comments

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.

Shakeskeyboarde avatar May 16 '24 18:05 Shakeskeyboarde

Hi @Shakeskeyboarde,

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

ehmicky avatar May 17 '24 02:05 ehmicky

This was released in 9.2.0.

ehmicky avatar Jun 06 '24 18:06 ehmicky