Skip to content

Commit f5d3337

Browse files
committed
Improve stream class definitions with inheritance
1 parent 0f744c8 commit f5d3337

File tree

4 files changed

+9
-91
lines changed

4 files changed

+9
-91
lines changed

0.10/node.d.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ declare module "stream" {
21592159
}
21602160

21612161
// Note: Duplex extends both Readable and Writable.
2162-
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
2162+
export class Duplex extends Readable implements Writable {
21632163
writable: boolean;
21642164
constructor(opts?: DuplexOptions);
21652165
_write(data: Buffer, encoding: string, callback: Function): void;
@@ -2175,31 +2175,9 @@ declare module "stream" {
21752175

21762176
export interface TransformOptions extends ReadableOptions, WritableOptions { }
21772177

2178-
// Note: Transform lacks the _read and _write methods of Readable/Writable.
2179-
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
2180-
readable: boolean;
2181-
writable: boolean;
2178+
export class Transform extends Duplex {
21822179
constructor(opts?: TransformOptions);
2183-
_transform(chunk: Buffer, encoding: string, callback: Function): void;
2184-
_transform(chunk: string, encoding: string, callback: Function): void;
2185-
_flush(callback: Function): void;
2186-
read(size?: number): any;
2187-
setEncoding(encoding: string): void;
2188-
pause(): void;
2189-
resume(): void;
2190-
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
2191-
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
2192-
unshift(chunk: string): void;
2193-
unshift(chunk: Buffer): void;
2194-
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
2195-
push(chunk: any, encoding?: string): boolean;
2196-
write(buffer: Buffer, cb?: Function): boolean;
2197-
write(str: string, cb?: Function): boolean;
2198-
write(str: string, encoding?: string, cb?: Function): boolean;
2199-
end(): void;
2200-
end(buffer: Buffer, cb?: Function): void;
2201-
end(str: string, cb?: Function): void;
2202-
end(str: string, encoding?: string, cb?: Function): void;
2180+
_transform(chunk: any, encoding: string, callback: Function): void;
22032181
}
22042182

22052183
export class PassThrough extends Transform { }

0.12/node.d.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,7 @@ declare module "stream" {
27722772
}
27732773

27742774
// Note: Duplex extends both Readable and Writable.
2775-
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
2775+
export class Duplex extends Readable implements Writable {
27762776
writable: boolean;
27772777
constructor(opts?: DuplexOptions);
27782778
setDefaultEncoding(encoding: string): this;
@@ -2786,29 +2786,9 @@ declare module "stream" {
27862786

27872787
export interface TransformOptions extends ReadableOptions, WritableOptions { }
27882788

2789-
// Note: Transform lacks the _read and _write methods of Readable/Writable.
2790-
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
2791-
readable: boolean;
2792-
writable: boolean;
2789+
export class Transform extends Duplex {
27932790
constructor(opts?: TransformOptions);
27942791
_transform(chunk: any, encoding: string, callback: Function): void;
2795-
_flush(callback: Function): void;
2796-
read(size?: number): any;
2797-
setDefaultEncoding(encoding: string): this;
2798-
setEncoding(encoding: string): this;
2799-
isPaused(): boolean;
2800-
pause(): this;
2801-
resume(): this;
2802-
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
2803-
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
2804-
unshift(chunk: any): void;
2805-
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
2806-
push(chunk: any, encoding?: string): boolean;
2807-
write(chunk: any, cb?: Function): boolean;
2808-
write(chunk: any, encoding?: string, cb?: Function): boolean;
2809-
end(): void;
2810-
end(chunk: any, cb?: Function): void;
2811-
end(chunk: any, encoding?: string, cb?: Function): void;
28122792
}
28132793

28142794
export class PassThrough extends Transform { }

4.0/node.d.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,7 +3017,7 @@ declare module "stream" {
30173017
}
30183018

30193019
// Note: Duplex extends both Readable and Writable.
3020-
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
3020+
export class Duplex extends Readable implements Writable {
30213021
writable: boolean;
30223022
constructor(opts?: DuplexOptions);
30233023
setDefaultEncoding(encoding: string): this;
@@ -3034,29 +3034,9 @@ declare module "stream" {
30343034
writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any;
30353035
}
30363036

3037-
// Note: Transform lacks the _read and _write methods of Readable/Writable.
3038-
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
3039-
readable: boolean;
3040-
writable: boolean;
3037+
export class Transform extends Duplex {
30413038
constructor(opts?: TransformOptions);
30423039
_transform(chunk: any, encoding: string, callback: Function): void;
3043-
_flush(callback: Function): void;
3044-
read(size?: number): any;
3045-
isPaused(): boolean;
3046-
setDefaultEncoding(encoding: string): this;
3047-
setEncoding(encoding: string): this;
3048-
pause(): this;
3049-
resume(): this;
3050-
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
3051-
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
3052-
unshift(chunk: any): void;
3053-
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
3054-
push(chunk: any, encoding?: string): boolean;
3055-
write(chunk: any, cb?: Function): boolean;
3056-
write(chunk: any, encoding?: string, cb?: Function): boolean;
3057-
end(): void;
3058-
end(chunk: any, cb?: Function): void;
3059-
end(chunk: any, encoding?: string, cb?: Function): void;
30603040
}
30613041

30623042
export class PassThrough extends Transform { }

6.0/node.d.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,7 @@ declare module "stream" {
31523152
}
31533153

31543154
// Note: Duplex extends both Readable and Writable.
3155-
export class Duplex extends Readable implements NodeJS.ReadWriteStream {
3155+
export class Duplex extends Readable implements Writable {
31563156
writable: boolean;
31573157
constructor(opts?: DuplexOptions);
31583158
setDefaultEncoding(encoding: string): this;
@@ -3169,29 +3169,9 @@ declare module "stream" {
31693169
writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any;
31703170
}
31713171

3172-
// Note: Transform lacks the _read and _write methods of Readable/Writable.
3173-
export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
3174-
readable: boolean;
3175-
writable: boolean;
3172+
export class Transform extends Duplex {
31763173
constructor(opts?: TransformOptions);
31773174
_transform(chunk: any, encoding: string, callback: Function): void;
3178-
_flush(callback: Function): void;
3179-
read(size?: number): any;
3180-
setEncoding(encoding: string): this;
3181-
setDefaultEncoding(encoding: string): this;
3182-
isPaused(): boolean;
3183-
pause(): this;
3184-
resume(): this;
3185-
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
3186-
unpipe<T extends NodeJS.WritableStream>(destination?: T): void;
3187-
unshift(chunk: any): void;
3188-
wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
3189-
push(chunk: any, encoding?: string): boolean;
3190-
write(chunk: any, cb?: Function): boolean;
3191-
write(chunk: any, encoding?: string, cb?: Function): boolean;
3192-
end(): void;
3193-
end(chunk: any, cb?: Function): void;
3194-
end(chunk: any, encoding?: string, cb?: Function): void;
31953175
}
31963176

31973177
export class PassThrough extends Transform { }

0 commit comments

Comments
 (0)