Skip to content
Myr

Fix types for `stdio: [..., undefined]` (#952)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent ed052d4 · Browse files · 4 files+46 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+46 added−4 removed

  • tests:+6 added−0 removed
  • other:+40 added−4 removed

4 files+46 added−4 removed

modified:lib/stdio/option.js+4 added
modified:test/stdio/forward.js+6 added
modified:index.d.ts+10 added-4 removed
7 unmodified lines
8type Unless<Condition extends boolean, ThenValue, ElseValue = never> = Condition extends true ? ElseValue : ThenValue;910type AndUnless<Condition extends boolean, ThenValue, ElseValue = unknown> = Condition extends true ? ElseValue : ThenValue;1112type IsMainFd<FdNumber extends string> = FdNumber extends keyof StreamOptionsNames ? true : false;1314// When the `stdin`/`stdout`/`stderr`/`stdio` option is set to one of those values, no stream is created13type NoStreamStdioOption =15type NoStreamStdioOption<FdNumber extends string> =16 | 'ignore'17 | 'inherit'18 | 'ipc'19 | number20 | Readable21 | Writable20 | [NoStreamStdioOption];22 | Unless<IsMainFd<FdNumber>, undefined>23 | readonly [NoStreamStdioOption<FdNumber>];2425type BaseStdioOption<26 IsSync extends boolean = boolean,27 IsArray extends boolean = boolean,
172 unmodified lines
200// Whether `result.stdout|stderr|all` is `undefined`, excluding the `buffer` option201type IgnoresStreamResult<202 FdNumber extends string,203 OptionsType extends CommonOptions = CommonOptions,201> = IgnoresStdioResult<StreamOption<FdNumber, OptionsType>>;204> = IgnoresStdioResult<FdNumber, StreamOption<FdNumber, OptionsType>>;205206// Whether `result.stdio[*]` is `undefined`204type IgnoresStdioResult<StdioOptionType extends StdioOptionCommon> = StdioOptionType extends NoStreamStdioOption ? true : false;207type IgnoresStdioResult<208 FdNumber extends string,209 StdioOptionType extends StdioOptionCommon,210> = StdioOptionType extends NoStreamStdioOption<FdNumber> ? true : false;211212// Whether `result.stdout|stderr|all` is `undefined`213type IgnoresStreamOutput<214 FdNumber extends string,
1444 unmodified lines
modified:index.test-d.ts+26 added
711 unmodified lines
712 expectType<string>(streamArrayStderrResult.stdout);713 expectType<undefined>(streamArrayStderrResult.stderr);714 expectType<string>(streamArrayStderrResult.all);715716 const undefinedStdoutResult = await execa('unicorns', {stdout: undefined, all: true});717 expectType<string>(undefinedStdoutResult.stdout);718 expectType<string>(undefinedStdoutResult.stderr);719 expectType<string>(undefinedStdoutResult.all);720721 const undefinedArrayStdoutResult = await execa('unicorns', {stdout: [undefined] as const, all: true});722 expectType<string>(undefinedArrayStdoutResult.stdout);723 expectType<string>(undefinedArrayStdoutResult.stderr);724 expectType<string>(undefinedArrayStdoutResult.all);725726 const undefinedStderrResult = await execa('unicorns', {stderr: undefined, all: true});727 expectType<string>(undefinedStderrResult.stdout);728 expectType<string>(undefinedStderrResult.stderr);729 expectType<string>(undefinedStderrResult.all);730731 const undefinedArrayStderrResult = await execa('unicorns', {stderr: [undefined] as const, all: true});732 expectType<string>(undefinedArrayStderrResult.stdout);733 expectType<string>(undefinedArrayStderrResult.stderr);734 expectType<string>(undefinedArrayStderrResult.all);735736 const fd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe']});737 expectType<string>(fd3Result.stdio[3]);738739 const inputFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', ['pipe', new Readable()]]});
16 unmodified lines
756757 const ignoreFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ignore']});758 expectType<undefined>(ignoreFd3Result.stdio[3]);759760 const undefinedFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', undefined]});761 expectType<undefined>(undefinedFd3Result.stdio[3]);762763 const undefinedArrayFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [undefined] as const]});764 expectType<undefined>(undefinedArrayFd3Result.stdio[3]);765766 const objectTransformLinesStdoutResult = await execa('unicorns', {lines: true, stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});767 expectType<unknown[]>(objectTransformLinesStdoutResult.stdout);768 expectType<[undefined, unknown[], string[]]>(objectTransformLinesStdoutResult.stdio);769
2928 unmodified lines