mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Add overloads to child_process.spawn for when options.stdio is a tuple of 3 (#37946)
* Add overloads to child_process.spawn for when options.stdio is a tuple of 3 * Update definition to be compatible with older versions of TypeScript * Fix tslint
This commit is contained in:
108
types/node/child_process.d.ts
vendored
108
types/node/child_process.d.ts
vendored
@@ -92,6 +92,24 @@ declare module "child_process" {
|
||||
];
|
||||
}
|
||||
|
||||
// return this object when stdio option is a tuple of 3
|
||||
interface ChildProcessByStdio<
|
||||
I extends null | Writable,
|
||||
O extends null | Readable,
|
||||
E extends null | Readable,
|
||||
> extends ChildProcess {
|
||||
stdin: I;
|
||||
stdout: O;
|
||||
stderr: E;
|
||||
readonly stdio: [
|
||||
I,
|
||||
O,
|
||||
E,
|
||||
Readable | Writable | null | undefined, // extra, no modification
|
||||
Readable | Writable | null | undefined // extra, no modification
|
||||
];
|
||||
}
|
||||
|
||||
interface MessageOptions {
|
||||
keepOpen?: boolean;
|
||||
}
|
||||
@@ -128,9 +146,99 @@ declare module "child_process" {
|
||||
stdio?: 'pipe' | Array<null | undefined | 'pipe'>;
|
||||
}
|
||||
|
||||
type StdioNull = 'inherit' | 'ignore' | Stream;
|
||||
type StdioPipe = undefined | null | 'pipe';
|
||||
|
||||
interface SpawnOptionsWithStdioTuple<
|
||||
Stdin extends StdioNull | StdioPipe,
|
||||
Stdout extends StdioNull | StdioPipe,
|
||||
Stderr extends StdioNull | StdioPipe,
|
||||
> extends SpawnOptions {
|
||||
stdio: [Stdin, Stdout, Stderr];
|
||||
}
|
||||
|
||||
// overloads of spawn without 'args'
|
||||
function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
||||
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<null, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, null, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<null, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<null, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<null, null, null>;
|
||||
|
||||
function spawn(command: string, options: SpawnOptions): ChildProcess;
|
||||
|
||||
// overloads of spawn with 'args'
|
||||
function spawn(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
||||
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<null, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, null, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<null, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<null, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<null, null, null>;
|
||||
|
||||
function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptions): ChildProcess;
|
||||
|
||||
interface ExecOptions extends CommonOptions {
|
||||
|
||||
@@ -308,6 +308,57 @@ async function testPromisify() {
|
||||
expectNonNull(childProcess.spawn('command', ['a', 'b', 'c'], { stdio: [null, null, null] }));
|
||||
expectNonNull(childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['pipe', 'pipe', 'pipe'] }));
|
||||
|
||||
function expectStdio<Stdin, Stdout, Stderr>(...cps: Array<{
|
||||
stdin: Stdin,
|
||||
stdout: Stdout,
|
||||
stderr: Stderr,
|
||||
stdio: [Stdin, Stdout, Stderr, any, any]
|
||||
}>): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
expectStdio<Writable, Readable, Readable>(
|
||||
childProcess.spawn('command', { stdio: ['pipe', 'pipe', 'pipe'] }),
|
||||
childProcess.spawn('command', { stdio: [null, null, null] }),
|
||||
childProcess.spawn('command', { stdio: [undefined, undefined, undefined] }),
|
||||
childProcess.spawn('command', { stdio: ['pipe', null, undefined] }),
|
||||
);
|
||||
|
||||
expectStdio<Writable, Readable, null>(
|
||||
childProcess.spawn('command', { stdio: ['pipe', 'pipe', 'ignore'] }),
|
||||
childProcess.spawn('command', { stdio: [null, null, 'inherit'] }),
|
||||
childProcess.spawn('command', { stdio: [undefined, undefined, process.stdout] }),
|
||||
childProcess.spawn('command', { stdio: ['pipe', null, process.stderr] }),
|
||||
);
|
||||
|
||||
expectStdio<null, null, null>(
|
||||
childProcess.spawn('command', { stdio: ['ignore', 'ignore', 'ignore'] }),
|
||||
childProcess.spawn('command', { stdio: ['inherit', 'inherit', 'inherit'] }),
|
||||
childProcess.spawn('command', { stdio: [process.stdin, process.stdout, process.stderr] }),
|
||||
childProcess.spawn('command', { stdio: ['ignore', 'inherit', process.stderr] }),
|
||||
);
|
||||
|
||||
expectStdio<Writable, Readable, Readable>(
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['pipe', 'pipe', 'pipe'] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: [null, null, null] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: [undefined, undefined, undefined] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['pipe', null, undefined] }),
|
||||
);
|
||||
|
||||
expectStdio<Writable, Readable, null>(
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['pipe', 'pipe', 'ignore'] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: [null, null, 'inherit'] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: [undefined, undefined, process.stdout] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['pipe', null, process.stderr] }),
|
||||
);
|
||||
|
||||
expectStdio<null, null, null>(
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['ignore', 'ignore', 'ignore'] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['inherit', 'inherit', 'inherit'] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: [process.stdin, process.stdout, process.stderr] }),
|
||||
childProcess.spawn('command', ['a', 'b', 'c'], { stdio: ['ignore', 'inherit', process.stderr] }),
|
||||
);
|
||||
|
||||
function expectChildProcess(cp: childProcess.ChildProcess): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user