diff --git a/types/firebird/firebird-tests.ts b/types/firebird/firebird-tests.ts index 96600a7f2d..d248fe427c 100644 --- a/types/firebird/firebird-tests.ts +++ b/types/firebird/firebird-tests.ts @@ -119,4 +119,4 @@ blob._write(buffer, 10); blob._write(buffer, 10, (err: Error | null) => {}); /* Stream */ -const strm: NodeJS.ReadWriteStream = new fb.Stream(blob); +const strm = new fb.Stream(blob); diff --git a/types/firebird/index.d.ts b/types/firebird/index.d.ts index 430a3b3b60..eaa20682a6 100644 --- a/types/firebird/index.d.ts +++ b/types/firebird/index.d.ts @@ -12,6 +12,8 @@ * Original document is [here](https://www.npmjs.com/package/firebird). */ declare module 'firebird' { + import * as stream from 'stream'; + /** * @see createConnection() method will create Firebird Connection object for you */ @@ -453,24 +455,14 @@ declare module 'firebird' { * You may pipe strm to/from NodeJS Stream objects (fs or socket). * You may also look at [NodeJS Streams reference](https://nodejs.org/api/stream.html). */ - class Stream implements NodeJS.ReadWriteStream { + class Stream extends stream.Stream { constructor(blob: FBBlob); - - /* Following lines is JUST AS NodeJS.ReadStream, NodeJS.WriteStream, and NodeJS.Emmiter */ /* tslint:disable */ /* NodeJS.ReadStream */ readable: boolean; - read(size?: number): string | Buffer; - setEncoding(encoding: string | null): this; pause(): this; resume(): this; - isPaused(): boolean; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): this; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; /* NodeJS.WriteStream */ writable: boolean; @@ -480,22 +472,9 @@ declare module 'firebird' { end(buffer: Buffer, cb?: Function): void; end(str: string, cb?: Function): void; end(str: string, encoding?: string, cb?: Function): void; - - /* EventEmitter */ - addListener(event: string | symbol, listener: Function): this; - on(event: string | symbol, listener: Function): this; - once(event: string | symbol, listener: Function): this; - removeListener(event: string | symbol, listener: Function): this; - removeAllListeners(event?: string | symbol): this; - setMaxListeners(n: number): this; - getMaxListeners(): number; - listeners(event: string | symbol): Function[]; - emit(event: string | symbol, ...args: any[]): boolean; - listenerCount(type: string | symbol): number; - prependListener(event: string | symbol, listener: Function): this; - prependOnceListener(event: string | symbol, listener: Function): this; - eventNames(): (string | symbol)[]; + destroy(error?: Error): void; /* tslint:enable */ + check_destroyed(): void; } } diff --git a/types/hexo-fs/index.d.ts b/types/hexo-fs/index.d.ts index 896fbc24eb..237071d7c6 100644 --- a/types/hexo-fs/index.d.ts +++ b/types/hexo-fs/index.d.ts @@ -427,9 +427,7 @@ export function writeFile( export function writeFileSync(path: string, data: any, options?: string | { encoding?: string | null; mode?: string | number; flag?: string }): void; // Static classes -export let Stats: Stats; -export let ReadStream: ReadStream; -export let WriteStream: WriteStream; +export { Stats, ReadStream, WriteStream } from 'graceful-fs'; // util export function escapeEOL(str: string): string; diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 6189d0b486..7f619fe377 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -345,7 +345,7 @@ declare namespace NodeJS { unpipe(destination?: T): this; unshift(chunk: string): void; unshift(chunk: Buffer): void; - wrap(oldStream: ReadableStream): ReadableStream; + wrap(oldStream: ReadableStream): this; } export interface WritableStream extends EventEmitter { @@ -438,10 +438,21 @@ declare namespace NodeJS { export interface WriteStream extends Socket { columns?: number; rows?: number; + _write(chunk: any, encoding: string, callback: Function): void; + _destroy(err: Error, callback: Function): void; + _final(callback: Function): void; + setDefaultEncoding(encoding: string): this; + cork(): void; + uncork(): void; + destroy(error?: Error): void; } export interface ReadStream extends Socket { isRaw?: boolean; setRawMode?(mode: boolean): void; + _read(size: number): void; + _destroy(err: Error, callback: Function): void; + push(chunk: any, encoding?: string): boolean; + destroy(error?: Error): void; } export interface Process extends EventEmitter { @@ -2430,7 +2441,9 @@ declare module "net" { export type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts; - export interface Socket extends stream.Duplex { + export class Socket extends stream.Duplex { + constructor(options?: { fd?: number; allowHalfOpen?: boolean; readable?: boolean; writable?: boolean; }); + // Extended base methods write(buffer: Buffer): boolean; write(buffer: Buffer, cb?: Function): boolean; @@ -2544,10 +2557,6 @@ declare module "net" { prependOnceListener(event: "timeout", listener: () => void): this; } - export var Socket: { - new(options?: SocketConstructorOpts): Socket; - }; - export interface ListenOptions { port?: number; host?: string; @@ -2679,7 +2688,7 @@ declare module "dgram" { export function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; export function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - export interface Socket extends events.EventEmitter { + export class Socket extends events.EventEmitter { send(msg: Buffer | String | any[], port: number, address: string, callback?: (error: Error | null, bytes: number) => void): void; send(msg: Buffer | String | any[], offset: number, length: number, port: number, address: string, callback?: (error: Error | null, bytes: number) => void): void; bind(port?: number, address?: string, callback?: () => void): void; @@ -2757,7 +2766,7 @@ declare module "fs" { */ export type PathLike = string | Buffer | URL; - export interface Stats { + export class Stats { isFile(): boolean; isDirectory(): boolean; isBlockDevice(): boolean; @@ -2814,7 +2823,7 @@ declare module "fs" { prependOnceListener(event: "error", listener: (error: Error) => void): this; } - export interface ReadStream extends stream.Readable { + export class ReadStream extends stream.Readable { close(): void; destroy(): void; bytesRead: number; @@ -2846,7 +2855,7 @@ declare module "fs" { prependOnceListener(event: "close", listener: () => void): this; } - export interface WriteStream extends stream.Writable { + export class WriteStream extends stream.Writable { close(): void; bytesWritten: number; path: string | Buffer; @@ -5084,7 +5093,7 @@ declare module "stream" { isPaused(): boolean; unpipe(destination?: T): this; unshift(chunk: any): void; - wrap(oldStream: NodeJS.ReadableStream): Readable; + wrap(oldStream: NodeJS.ReadableStream): this; push(chunk: any, encoding?: string): boolean; _destroy(err: Error, callback: Function): void; destroy(error?: Error): void; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index 0e2823ac1c..7883ef10f2 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -2066,6 +2066,36 @@ namespace child_process_tests { let _sendHandle: net.Socket | net.Server = sendHandle; }); } + { + process.stdin.setEncoding('utf8'); + + process.stdin.on('readable', () => { + const chunk = process.stdin.read(); + if (chunk !== null) { + process.stdout.write(`data: ${chunk}`); + } + }); + + process.stdin.on('end', () => { + process.stdout.write('end'); + }); + + process.stdin.pipe(process.stdout); + + console.log(process.stdin.isTTY); + console.log(process.stdout.isTTY); + + console.log(process.stdin instanceof net.Socket); + console.log(process.stdout instanceof fs.ReadStream); + + var stdin: stream.Readable = process.stdin; + console.log(stdin instanceof net.Socket); + console.log(stdin instanceof fs.ReadStream); + + var stdout: stream.Writable = process.stdout; + console.log(stdout instanceof net.Socket); + console.log(stdout instanceof fs.WriteStream); + } } ////////////////////////////////////////////////////////////////////// diff --git a/types/vinyl/vinyl-tests.ts b/types/vinyl/vinyl-tests.ts index f9e71dd532..2fe95e9404 100644 --- a/types/vinyl/vinyl-tests.ts +++ b/types/vinyl/vinyl-tests.ts @@ -24,10 +24,6 @@ interface TestFile extends File { _base?: string; } -declare module 'fs' { - class Stats { } -} - var pipe: (streams: [NodeJS.ReadableStream, NodeJS.WritableStream], cb: (err?: Error) => void) => void = miss.pipe; var from: (values: any[]) => NodeJS.ReadableStream = miss.from; var concat: (fn: (d: Buffer) => void) => NodeJS.WritableStream = miss.concat;