diff --git a/types/node/index.d.ts b/types/node/index.d.ts index bb4b54efa7..f39dc1dc74 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -1151,7 +1151,6 @@ declare module "http" { constructor(); setTimeout(msecs: number, callback?: () => void): this; - destroy(error: Error): void; setHeader(name: string, value: number | string | string[]): void; getHeader(name: string): number | string | string[] | undefined; getHeaders(): OutgoingHttpHeaders; @@ -2777,7 +2776,6 @@ declare module "net" { bufferSize: number; setEncoding(encoding?: string): this; - destroy(err?: any): void; pause(): this; resume(): this; setTimeout(timeout: number, callback?: Function): this; @@ -3143,7 +3141,6 @@ declare module "fs" { export class ReadStream extends stream.Readable { close(): void; - destroy(): void; bytesRead: number; path: string | Buffer; @@ -5978,8 +5975,8 @@ declare module "stream" { highWaterMark?: number; encoding?: string; objectMode?: boolean; - read?: (this: Readable, size?: number) => any; - destroy?: (error: Error | null, callback: (error?: Error) => void) => void; + read?(this: Readable, size: number): void; + destroy?(this: Readable, error: Error | null, callback: (error: Error | null) => void): void; } export class Readable extends Stream implements NodeJS.ReadableStream { @@ -5997,7 +5994,7 @@ declare module "stream" { unshift(chunk: any): void; wrap(oldStream: NodeJS.ReadableStream): this; push(chunk: any, encoding?: string): boolean; - _destroy(error: Error | null, callback: (error?: Error) => void): void; + _destroy(error: Error | null, callback: (error: Error | null) => void): void; destroy(error?: Error): void; /** @@ -6009,66 +6006,66 @@ declare module "stream" { * 4. readable * 5. error */ - addListener(event: string, listener: (...args: any[]) => void): this; addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "data", listener: (chunk: any) => void): this; addListener(event: "end", listener: () => void): this; addListener(event: "readable", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; + addListener(event: string | symbol, listener: (...args: any[]) => void): this; - emit(event: string | symbol, ...args: any[]): boolean; emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "data", chunk: any): boolean; emit(event: "end"): boolean; emit(event: "readable"): boolean; emit(event: "error", err: Error): boolean; + emit(event: string | symbol, ...args: any[]): boolean; - on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "data", listener: (chunk: any) => void): this; on(event: "end", listener: () => void): this; on(event: "readable", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; + on(event: string | symbol, listener: (...args: any[]) => void): this; - once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "data", listener: (chunk: any) => void): this; once(event: "end", listener: () => void): this; once(event: "readable", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; + once(event: string | symbol, listener: (...args: any[]) => void): this; - prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "data", listener: (chunk: any) => void): this; prependListener(event: "end", listener: () => void): this; prependListener(event: "readable", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; + prependListener(event: string | symbol, listener: (...args: any[]) => void): this; - prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "data", listener: (chunk: any) => void): this; prependOnceListener(event: "end", listener: () => void): this; prependOnceListener(event: "readable", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; + prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; - removeListener(event: string, listener: (...args: any[]) => void): this; removeListener(event: "close", listener: () => void): this; - removeListener(event: "data", listener: (chunk: Buffer | string) => void): this; + removeListener(event: "data", listener: (chunk: any) => void): this; removeListener(event: "end", listener: () => void): this; removeListener(event: "readable", listener: () => void): this; removeListener(event: "error", listener: (err: Error) => void): this; + removeListener(event: string | symbol, listener: (...args: any[]) => void): this; - [Symbol.asyncIterator](): AsyncIterableIterator; + [Symbol.asyncIterator](): AsyncIterableIterator; } export interface WritableOptions { highWaterMark?: number; decodeStrings?: boolean; objectMode?: boolean; - write?: (chunk: any, encoding: string, callback: Function) => any; - writev?: (chunks: Array<{ chunk: any, encoding: string }>, callback: Function) => any; - destroy?: (error: Error | null, callback: (error?: Error) => void) => void; - final?: (callback: (error?: Error) => void) => void; + write?(this: Writable, chunk: any, encoding: string, callback: (error?: Error | null) => void): void; + writev?(this: Writable, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void; + destroy?(this: Writable, error: Error | null, callback: (error: Error | null) => void): void; + final?(this: Writable, callback: (error?: Error | null) => void): void; } export class Writable extends Stream implements NodeJS.WritableStream { @@ -6076,16 +6073,16 @@ declare module "stream" { readonly writableHighWaterMark: number; readonly writableLength: number; constructor(opts?: WritableOptions); - _write(chunk: any, encoding: string, callback: (err?: Error) => void): void; - _writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (err?: Error) => void): void; - _destroy(error: Error | null, callback: (error?: Error) => void): void; - _final(callback: Function): void; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; + _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void; + _writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void; + _destroy(error: Error | null, callback: (error: Error | null) => void): void; + _final(callback: (error?: Error | null) => void): void; + write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean; + write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean; setDefaultEncoding(encoding: string): this; - end(cb?: Function): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; + end(cb?: () => void): void; + end(chunk: any, cb?: () => void): void; + end(chunk: any, encoding?: string, cb?: () => void): void; cork(): void; uncork(): void; destroy(error?: Error): void; @@ -6100,67 +6097,72 @@ declare module "stream" { * 5. pipe * 6. unpipe */ - addListener(event: string, listener: (...args: any[]) => void): this; addListener(event: "close", listener: () => void): this; addListener(event: "drain", listener: () => void): this; addListener(event: "error", listener: (err: Error) => void): this; addListener(event: "finish", listener: () => void): this; addListener(event: "pipe", listener: (src: Readable) => void): this; addListener(event: "unpipe", listener: (src: Readable) => void): this; + addListener(event: string | symbol, listener: (...args: any[]) => void): this; - emit(event: string | symbol, ...args: any[]): boolean; emit(event: "close"): boolean; - emit(event: "drain", chunk: Buffer | string): boolean; + emit(event: "drain"): boolean; emit(event: "error", err: Error): boolean; emit(event: "finish"): boolean; emit(event: "pipe", src: Readable): boolean; emit(event: "unpipe", src: Readable): boolean; + emit(event: string | symbol, ...args: any[]): boolean; - on(event: string, listener: (...args: any[]) => void): this; on(event: "close", listener: () => void): this; on(event: "drain", listener: () => void): this; on(event: "error", listener: (err: Error) => void): this; on(event: "finish", listener: () => void): this; on(event: "pipe", listener: (src: Readable) => void): this; on(event: "unpipe", listener: (src: Readable) => void): this; + on(event: string | symbol, listener: (...args: any[]) => void): this; - once(event: string, listener: (...args: any[]) => void): this; once(event: "close", listener: () => void): this; once(event: "drain", listener: () => void): this; once(event: "error", listener: (err: Error) => void): this; once(event: "finish", listener: () => void): this; once(event: "pipe", listener: (src: Readable) => void): this; once(event: "unpipe", listener: (src: Readable) => void): this; + once(event: string | symbol, listener: (...args: any[]) => void): this; - prependListener(event: string, listener: (...args: any[]) => void): this; prependListener(event: "close", listener: () => void): this; prependListener(event: "drain", listener: () => void): this; prependListener(event: "error", listener: (err: Error) => void): this; prependListener(event: "finish", listener: () => void): this; prependListener(event: "pipe", listener: (src: Readable) => void): this; prependListener(event: "unpipe", listener: (src: Readable) => void): this; + prependListener(event: string | symbol, listener: (...args: any[]) => void): this; - prependOnceListener(event: string, listener: (...args: any[]) => void): this; prependOnceListener(event: "close", listener: () => void): this; prependOnceListener(event: "drain", listener: () => void): this; prependOnceListener(event: "error", listener: (err: Error) => void): this; prependOnceListener(event: "finish", listener: () => void): this; prependOnceListener(event: "pipe", listener: (src: Readable) => void): this; prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this; + prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; - removeListener(event: string, listener: (...args: any[]) => void): this; removeListener(event: "close", listener: () => void): this; removeListener(event: "drain", listener: () => void): this; removeListener(event: "error", listener: (err: Error) => void): this; removeListener(event: "finish", listener: () => void): this; removeListener(event: "pipe", listener: (src: Readable) => void): this; removeListener(event: "unpipe", listener: (src: Readable) => void): this; + removeListener(event: string | symbol, listener: (...args: any[]) => void): this; } export interface DuplexOptions extends ReadableOptions, WritableOptions { allowHalfOpen?: boolean; readableObjectMode?: boolean; writableObjectMode?: boolean; + read?(this: Duplex, size: number): void; + write?(this: Duplex, chunk: any, encoding: string, callback: (error?: Error | null) => void): void; + writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void; + final?(this: Duplex, callback: (error?: Error | null) => void): void; + destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void; } // Note: Duplex extends both Readable and Writable. @@ -6169,31 +6171,36 @@ declare module "stream" { readonly writableHighWaterMark: number; readonly writableLength: number; constructor(opts?: DuplexOptions); - _write(chunk: any, encoding: string, callback: (err?: Error) => void): void; - _writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (err?: Error) => void): void; - _destroy(error: Error | null, callback: (error?: Error) => void): void; - _final(callback: Function): void; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; + _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void; + _writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void; + _destroy(error: Error | null, callback: (error: Error | null) => void): void; + _final(callback: (error?: Error | null) => void): void; + write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean; + write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean; setDefaultEncoding(encoding: string): this; - end(cb?: Function): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; + end(cb?: () => void): void; + end(chunk: any, cb?: () => void): void; + end(chunk: any, encoding?: string, cb?: () => void): void; cork(): void; uncork(): void; } - type TransformCallback = (err?: Error, data?: any) => void; + type TransformCallback = (error?: Error, data?: any) => void; export interface TransformOptions extends DuplexOptions { - transform?: (chunk: any, encoding: string, callback: TransformCallback) => any; - flush?: (callback: TransformCallback) => any; + read?(this: Transform, size: number): void; + write?(this: Transform, chunk: any, encoding: string, callback: (error?: Error | null) => void): void; + writev?(this: Transform, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void; + final?(this: Transform, callback: (error?: Error | null) => void): void; + destroy?(this: Transform, error: Error | null, callback: (error: Error | null) => void): void; + transform?(this: Transform, chunk: any, encoding: string, callback: TransformCallback): void; + flush?(this: Transform, callback: TransformCallback): void; } export class Transform extends Duplex { constructor(opts?: TransformOptions); _transform(chunk: any, encoding: string, callback: TransformCallback): void; - destroy(error?: Error): void; + _flush(callback: TransformCallback): void; } export class PassThrough extends Transform { } diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index aae5512702..9c38a5672e 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -953,81 +953,149 @@ const unzipped: Buffer = zlib.unzipSync(compressMe); function simplified_stream_ctor_test() { new stream.Readable({ read(size) { - size.toFixed(); + // $ExpectType Readable + this; + // $ExpectType number + size; }, destroy(error, cb) { - error.stack; - cb(error); + // $ExpectType Error + error; + // $ExpectType (error: Error) => void + cb; } }); new stream.Writable({ write(chunk, enc, cb) { - chunk.slice(1); - enc.charAt(0); - cb(); + // $ExpectType Writable + this; + // $ExpectType any + chunk; + // $ExpectType string + enc; + // $ExpectType (error?: Error) => void + cb; }, writev(chunks, cb) { - chunks[0].chunk.slice(0); - chunks[0].encoding.charAt(0); - cb(); + // $ExpectType Writable + this; + // $ExpectType { chunk: any; encoding: string; }[] + chunks; + // $ExpectType (error?: Error) => void + cb; }, destroy(error, cb) { - error.stack; - cb(error); + // $ExpectType Writable + this; + // $ExpectType Error + error; + // $ExpectType (error: Error) => void + cb; }, final(cb) { - cb(null); + // $ExpectType Writable + this; + // $ExpectType (error?: Error) => void + cb; } }); new stream.Duplex({ read(size) { - size.toFixed(); + // $ExpectType Duplex + this; + // $ExpectType number + size; }, write(chunk, enc, cb) { - chunk.slice(1); - enc.charAt(0); - cb(); + // $ExpectType Duplex + this; + // $ExpectType any + chunk; + // $ExpectType string + enc; + // $ExpectType (error?: Error) => void + cb; }, writev(chunks, cb) { - chunks[0].chunk.slice(0); - chunks[0].encoding.charAt(0); - cb(); + // $ExpectType Duplex + this; + // $ExpectType { chunk: any; encoding: string; }[] + chunks; + // $ExpectType (error?: Error) => void + cb; }, destroy(error, cb) { - error.stack; - cb(error); + // $ExpectType Duplex + this; + // $ExpectType Error + error; + // $ExpectType (error: Error) => void + cb; + }, + final(cb) { + // $ExpectType Duplex + this; + // $ExpectType (error?: Error) => void + cb; }, readableObjectMode: true, writableObjectMode: true }); new stream.Transform({ - transform(chunk, enc, cb) { - chunk.slice(1); - enc.charAt(0); - cb(); - }, - flush(cb) { - cb(); - }, read(size) { - size.toFixed(); + // $ExpectType Transform + this; + // $ExpectType number + size; }, write(chunk, enc, cb) { - chunk.slice(1); - enc.charAt(0); - cb(); + // $ExpectType Transform + this; + // $ExpectType any + chunk; + // $ExpectType string + enc; + // $ExpectType (error?: Error) => void + cb; }, writev(chunks, cb) { - chunks[0].chunk.slice(0); - chunks[0].encoding.charAt(0); - cb(); + // $ExpectType Transform + this; + // $ExpectType { chunk: any; encoding: string; }[] + chunks; + // $ExpectType (error?: Error) => void + cb; }, destroy(error, cb) { - error.stack; - cb(error); + // $ExpectType Transform + this; + // $ExpectType Error + error; + // $ExpectType (error: Error) => void + cb; + }, + final(cb) { + // $ExpectType Transform + this; + // $ExpectType (error?: Error) => void + cb; + }, + transform(chunk, enc, cb) { + // $ExpectType Transform + this; + // $ExpectType any + chunk; + // $ExpectType string + enc; + // $ExpectType TransformCallback + cb; + }, + flush(cb) { + // $ExpectType TransformCallback + cb; }, allowHalfOpen: true, readableObjectMode: true, diff --git a/types/vinyl-fs/index.d.ts b/types/vinyl-fs/index.d.ts index d3b13baeaa..d35dd6bcef 100644 --- a/types/vinyl-fs/index.d.ts +++ b/types/vinyl-fs/index.d.ts @@ -9,7 +9,7 @@ declare global { namespace NodeJS { interface WritableStream { - write(buffer: any/* Vinyl.File */, cb?: (err?: Error) => void): boolean; + write(buffer: any/* Vinyl.File */, cb?: (err?: Error | null) => void): boolean; } } }