Improve types of `childProcess.stdout` and `childProcess.stderr` (#687)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent ec383fe · Browse files · 2 files·+39 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+39 added−7 removed
- other:+39 added−7 removed
Provenance
- Commit
8062913- Tree
856c91e- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
ec383fe
2 files changed+39 added−7 removed
modified:index.d.ts+9 added
623 unmodified lines624 */625 forceKillAfterTimeout?: number | false;626 };627 628+type StreamUnlessIgnored<629+ StreamIndex extends string,630+ OptionsType extends Options = Options,631+> = IgnoresStreamResult<StreamIndex, OptionsType> extends true ? null : Readable;632+633 export type ExecaChildPromise<OptionsType extends Options = Options> = {634+ stdout: StreamUnlessIgnored<'1', OptionsType>;635+636+ stderr: StreamUnlessIgnored<'2', OptionsType>;637+638 /**639 Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).640 641 This is `undefined` if either:525 unmodified linesmodified:index.test-d.ts+30 added-7 removed
78 unmodified lines79 expectType<string>(unicornsResult.stdio[2]);80 expectType<string | undefined>(unicornsResult.all);81 expectType<string | undefined>(unicornsResult.stdio[3 as number]);82 83+ expectType<Readable>(execaBufferPromise.stdout);84+ expectType<Readable>(execaBufferPromise.stderr);85 const bufferResult = await execaBufferPromise;86 expectType<Uint8Array>(bufferResult.stdout);87 expectType<Uint8Array>(bufferResult.stdio[1]);88 expectType<Uint8Array>(bufferResult.stderr);89 expectType<Uint8Array>(bufferResult.stdio[2]);90 expectType<Uint8Array | undefined>(bufferResult.all);91 90- const noBufferResult = await execa('unicorns', {buffer: false});92+ const noBufferPromise = execa('unicorns', {buffer: false});93+ expectType<Readable>(noBufferPromise.stdout);94+ expectType<Readable>(noBufferPromise.stderr);95+ const noBufferResult = await noBufferPromise;96 expectType<undefined>(noBufferResult.stdout);97 expectType<undefined>(noBufferResult.stdio[1]);98 expectType<undefined>(noBufferResult.stderr);99 expectType<undefined>(noBufferResult.stdio[2]);100 expectType<undefined>(noBufferResult.all);101 97- const multipleStdoutResult = await execa('unicorns', {stdout: ['inherit', 'pipe'] as ['inherit', 'pipe']});102+ const multipleStdoutPromise = execa('unicorns', {stdout: ['inherit', 'pipe'] as ['inherit', 'pipe']});103+ expectType<Readable>(multipleStdoutPromise.stdout);104+ expectType<Readable>(multipleStdoutPromise.stderr);105+ const multipleStdoutResult = await multipleStdoutPromise;106 expectType<string>(multipleStdoutResult.stdout);107 expectType<string>(multipleStdoutResult.stdio[1]);108 expectType<string>(multipleStdoutResult.stderr);109 expectType<string>(multipleStdoutResult.stdio[2]);110 expectType<string | undefined>(multipleStdoutResult.all);111 104- const ignoreBothResult = await execa('unicorns', {stdout: 'ignore', stderr: 'ignore'});112+ const ignoreBothPromise = execa('unicorns', {stdout: 'ignore', stderr: 'ignore'});113+ expectType<null>(ignoreBothPromise.stdout);114+ expectType<null>(ignoreBothPromise.stderr);115+ const ignoreBothResult = await ignoreBothPromise;116 expectType<undefined>(ignoreBothResult.stdout);117 expectType<undefined>(ignoreBothResult.stdio[1]);118 expectType<undefined>(ignoreBothResult.stderr);119 expectType<undefined>(ignoreBothResult.stdio[2]);120 expectType<undefined>(ignoreBothResult.all);121 111- const ignoreAllResult = await execa('unicorns', {stdio: 'ignore'});122+ const ignoreAllPromise = execa('unicorns', {stdio: 'ignore'});123+ expectType<null>(ignoreAllPromise.stdout);124+ expectType<null>(ignoreAllPromise.stderr);125+ const ignoreAllResult = await ignoreAllPromise;126 expectType<undefined>(ignoreAllResult.stdout);127 expectType<undefined>(ignoreAllResult.stdio[1]);128 expectType<undefined>(ignoreAllResult.stderr);129 expectType<undefined>(ignoreAllResult.stdio[2]);130 expectType<undefined>(ignoreAllResult.all);131 118- const ignoreStdioArrayResult = await execa('unicorns', {stdio: ['pipe', 'ignore', 'pipe']});132+ const ignoreStdioArrayPromise = execa('unicorns', {stdio: ['pipe', 'ignore', 'pipe']});133+ expectType<null>(ignoreStdioArrayPromise.stdout);134+ expectType<Readable>(ignoreStdioArrayPromise.stderr);135+ const ignoreStdioArrayResult = await ignoreStdioArrayPromise;136 expectType<undefined>(ignoreStdioArrayResult.stdout);137 expectType<undefined>(ignoreStdioArrayResult.stdio[1]);138 expectType<string>(ignoreStdioArrayResult.stderr);139 expectType<string>(ignoreStdioArrayResult.stdio[2]);140 expectType<string | undefined>(ignoreStdioArrayResult.all);141 125- const ignoreStdoutResult = await execa('unicorns', {stdout: 'ignore'});142+ const ignoreStdoutPromise = execa('unicorns', {stdout: 'ignore'});143+ expectType<null>(ignoreStdoutPromise.stdout);144+ expectType<Readable>(ignoreStdoutPromise.stderr);145+ const ignoreStdoutResult = await ignoreStdoutPromise;146 expectType<undefined>(ignoreStdoutResult.stdout);147 expectType<string>(ignoreStdoutResult.stderr);148 expectType<string | undefined>(ignoreStdoutResult.all);149 1 unmodified line151 expectType<undefined>(ignoreArrayStdoutResult.stdout);152 expectType<string>(ignoreArrayStdoutResult.stderr);153 expectType<string | undefined>(ignoreArrayStdoutResult.all);154 135- const ignoreStderrResult = await execa('unicorns', {stderr: 'ignore'});155+ const ignoreStderrPromise = execa('unicorns', {stderr: 'ignore'});156+ expectType<Readable>(ignoreStderrPromise.stdout);157+ expectType<null>(ignoreStderrPromise.stderr);158+ const ignoreStderrResult = await ignoreStderrPromise;159 expectType<string>(ignoreStderrResult.stdout);160 expectType<undefined>(ignoreStderrResult.stderr);161 expectType<string | undefined>(ignoreStderrResult.all);162 881 unmodified lines