node: add std* file descriptors constants (#46034)

* node: add file descriptors

* adjust types from other modules
This commit is contained in:
James Judd 2020-07-13 19:00:30 +10:00 committed by GitHub
parent 6ebf2f46d2
commit 806c044994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 5 deletions

View File

@ -5,5 +5,5 @@ const stream = fs.createReadStream('package.json');
// $ExpectType ReadStream
destroy(stream);
// $ExpectType WriteStream
// $ExpectType WriteStream & { fd: 2; }
destroy(process.stderr);

View File

@ -35,7 +35,7 @@ mp.end('bar', encoding);
mp.end('bar', encoding, () => {});
mp.resume();
mp.pause();
mp.pipe(process.stdout); // $ExpectType WriteStream
mp.pipe(process.stdout); // $ExpectType WriteStream & { fd: 1; }
mp.on('data', chunk => {
chunk; // $ExpectType any

View File

@ -174,12 +174,18 @@ declare module "process" {
/**
* Can also be a tty.WriteStream, not typed due to limitations.
*/
stdout: WriteStream;
stdout: WriteStream & {
fd: 1;
};
/**
* Can also be a tty.WriteStream, not typed due to limitations.
*/
stderr: WriteStream;
stdin: ReadStream;
stderr: WriteStream & {
fd: 2;
};
stdin: ReadStream & {
fd: 0;
};
openStdin(): Socket;
argv: string[];
argv0: string;

View File

@ -32,6 +32,10 @@ import { EventEmitter } from "events";
const listeners = process.listeners('uncaughtException');
const oldHandler = listeners[listeners.length - 1];
process.addListener('uncaughtException', oldHandler);
const stdInFd = process.stdin.fd;
const stdOutFd = process.stdout.fd;
const stdErrorFd = process.stderr.fd;
}
{
function myCb(err: Error): void {