Fix type of `childProcess.all` (#689)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 0438d35 · Browse files · 2 files·+32 added−3 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+32 added−3 removed
- other:+32 added−3 removed
Provenance
- Commit
07ce2ff- Tree
4752911- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
0438d35
2 files changed+32 added−3 removed
modified:index.d.ts+21 added-1 removed
662 unmodified lines663 type ChildProcessStream<StreamResultIgnored extends boolean> = StreamResultIgnored extends true664 ? null665 : Readable;666 667+type AllStream<OptionsType extends Options = Options> = AllStreamProperty<OptionsType['all'], OptionsType>;668+669+type AllStreamProperty<670+ AllOption extends Options['all'] = Options['all'],671+ OptionsType extends Options = Options,672+> = AllOption extends true673+ ? AllIfStdout<IgnoresStreamResult<'1', OptionsType>, OptionsType>674+ : undefined;675+676+type AllIfStdout<677+ StdoutResultIgnored extends boolean,678+ OptionsType extends Options = Options,679+> = StdoutResultIgnored extends true680+ ? AllIfStderr<IgnoresStreamResult<'2', OptionsType>>681+ : Readable;682+683+type AllIfStderr<StderrResultIgnored extends boolean> = StderrResultIgnored extends true684+ ? undefined685+ : Readable;686+687 export type ExecaChildPromise<OptionsType extends Options = Options> = {688 stdout: StreamUnlessIgnored<'1', OptionsType>;689 690 stderr: StreamUnlessIgnored<'2', OptionsType>;4 unmodified lines695 This is `undefined` if either:696 - the `all` option is `false` (the default value)697 - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)698 */679- all?: Readable;699+ all: AllStream<OptionsType>;700 701 catch<ResultType = never>(702 onRejected?: (reason: ExecaError<OptionsType>) => ResultType | PromiseLike<ResultType>703 ): Promise<ExecaReturnValue<OptionsType> | ResultType>;517 unmodified linesmodified:index.test-d.ts+11 added-2 removed
21 unmodified lines22 } from './index.js';23 24 expectType<Readable | null>({} as ExecaChildProcess['stdout']);25 expectType<Readable | null>({} as ExecaChildProcess['stderr']);26+expectType<Readable | undefined>({} as ExecaChildProcess['all']);27 expectType<string | Uint8Array | undefined>({} as ExecaReturnValue['stdout']);28 expectType<string | Uint8Array | undefined>({} as ExecaReturnValue['stderr']);29 expectType<string | Uint8Array | undefined>({} as ExecaReturnValue['all']);30 expectType<[undefined, string | Uint8Array | undefined, string | Uint8Array | undefined]>({} as ExecaReturnValue['stdio']);37 unmodified lines68 expectAssignable<ExecaChildProcess>(execaPromise.pipeAll!(execaBufferPromise));69 expectAssignable<ExecaChildProcess>(execaBufferPromise.pipeAll!(execaPromise));70 expectAssignable<ExecaChildProcess>(execaBufferPromise.pipeAll!(execaBufferPromise));71 71- expectType<Readable | undefined>(execaPromise.all);72+ expectType<Readable>(execaPromise.all);73 const noAllPromise = execa('unicorns');73- expectType<Readable | undefined>(noAllPromise.all);74+ expectType<undefined>(noAllPromise.all);75 const noAllResult = await noAllPromise;76 expectType<undefined>(noAllResult.all);77 78 const unicornsResult = await execaPromise;17 unmodified lines96 expectType<string | undefined>(unicornsResult.stdio[3 as number]);97 98 expectType<Readable>(execaBufferPromise.stdout);99 expectType<Readable>(execaBufferPromise.stderr);100+ expectType<Readable>(execaBufferPromise.all);101 const bufferResult = await execaBufferPromise;102 expectType<Uint8Array>(bufferResult.stdout);103 expectType<Uint8Array>(bufferResult.stdio[1]);104 expectType<Uint8Array>(bufferResult.stderr);2 unmodified lines107 108 const noBufferPromise = execa('unicorns', {buffer: false, all: true});109 expectType<Readable>(noBufferPromise.stdout);110 expectType<Readable>(noBufferPromise.stderr);111+ expectType<Readable>(noBufferPromise.all);112 const noBufferResult = await noBufferPromise;113 expectType<undefined>(noBufferResult.stdout);114 expectType<undefined>(noBufferResult.stdio[1]);115 expectType<undefined>(noBufferResult.stderr);2 unmodified lines118 119 const multipleStdoutPromise = execa('unicorns', {stdout: ['inherit', 'pipe'] as ['inherit', 'pipe'], all: true});120 expectType<Readable>(multipleStdoutPromise.stdout);121 expectType<Readable>(multipleStdoutPromise.stderr);122+ expectType<Readable>(multipleStdoutPromise.all);123 const multipleStdoutResult = await multipleStdoutPromise;124 expectType<string>(multipleStdoutResult.stdout);125 expectType<string>(multipleStdoutResult.stdio[1]);126 expectType<string>(multipleStdoutResult.stderr);2 unmodified lines129 130 const ignoreBothPromise = execa('unicorns', {stdout: 'ignore', stderr: 'ignore', all: true});131 expectType<null>(ignoreBothPromise.stdout);132 expectType<null>(ignoreBothPromise.stderr);133+ expectType<undefined>(ignoreBothPromise.all);134 const ignoreBothResult = await ignoreBothPromise;135 expectType<undefined>(ignoreBothResult.stdout);136 expectType<undefined>(ignoreBothResult.stdio[1]);137 expectType<undefined>(ignoreBothResult.stderr);2 unmodified lines140 141 const ignoreAllPromise = execa('unicorns', {stdio: 'ignore', all: true});142 expectType<null>(ignoreAllPromise.stdout);143 expectType<null>(ignoreAllPromise.stderr);144+ expectType<undefined>(ignoreAllPromise.all);145 const ignoreAllResult = await ignoreAllPromise;146 expectType<undefined>(ignoreAllResult.stdout);147 expectType<undefined>(ignoreAllResult.stdio[1]);148 expectType<undefined>(ignoreAllResult.stderr);2 unmodified lines151 152 const ignoreStdioArrayPromise = execa('unicorns', {stdio: ['pipe', 'ignore', 'pipe'], all: true});153 expectType<null>(ignoreStdioArrayPromise.stdout);154 expectType<Readable>(ignoreStdioArrayPromise.stderr);155+ expectType<Readable>(ignoreStdioArrayPromise.all);156 const ignoreStdioArrayResult = await ignoreStdioArrayPromise;157 expectType<undefined>(ignoreStdioArrayResult.stdout);158 expectType<undefined>(ignoreStdioArrayResult.stdio[1]);159 expectType<string>(ignoreStdioArrayResult.stderr);2 unmodified lines162 163 const ignoreStdoutPromise = execa('unicorns', {stdout: 'ignore', all: true});164 expectType<null>(ignoreStdoutPromise.stdout);165 expectType<Readable>(ignoreStdoutPromise.stderr);166+ expectType<Readable>(ignoreStdoutPromise.all);167 const ignoreStdoutResult = await ignoreStdoutPromise;168 expectType<undefined>(ignoreStdoutResult.stdout);169 expectType<string>(ignoreStdoutResult.stderr);170 expectType<string>(ignoreStdoutResult.all);5 unmodified lines176 177 const ignoreStderrPromise = execa('unicorns', {stderr: 'ignore', all: true});178 expectType<Readable>(ignoreStderrPromise.stdout);179 expectType<null>(ignoreStderrPromise.stderr);180+ expectType<Readable>(ignoreStderrPromise.all);181 const ignoreStderrResult = await ignoreStderrPromise;182 expectType<string>(ignoreStderrResult.stdout);183 expectType<undefined>(ignoreStderrResult.stderr);184 expectType<string>(ignoreStderrResult.all);909 unmodified lines