diff --git a/types/through2/index.d.ts b/types/through2/index.d.ts index 711eafeaed..3ff12ff86d 100644 --- a/types/through2/index.d.ts +++ b/types/through2/index.d.ts @@ -1,24 +1,22 @@ -// Type definitions for through2 v 2.0.0 +// Type definitions for through2 v 2.0 // Project: https://github.com/rvagg/through2 -// Definitions by: Bart van der Schoor , jedmao , Georgios Valotasios , Ben Chauvette +// Definitions by: Bart van der Schoor , jedmao , Georgios Valotasios +// Ben Chauvette < https://github.com/bdchauvette>, TeamworkGuy2 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// - - import stream = require('stream'); type TransformCallback = (err?: any, data?: any) => void; -type TransformFunction = (chunk: any, enc: string, callback: TransformCallback) => void; -type FlushCallback = (flushCallback: () => void) => void; +type TransformFunction = (this: stream.Transform, chunk: any, enc: string, callback: TransformCallback) => void; +type FlushCallback = (this: stream.Transform, flushCallback: () => void) => void; declare function through2(transform?: TransformFunction, flush?: FlushCallback): stream.Transform; - declare function through2(opts?: stream.DuplexOptions, transform?: TransformFunction, flush?: FlushCallback): stream.Transform; declare namespace through2 { - export interface Through2Constructor extends stream.Transform { + interface Through2Constructor extends stream.Transform { new (opts?: stream.DuplexOptions): stream.Transform; (opts?: stream.DuplexOptions): stream.Transform; } @@ -26,13 +24,14 @@ declare namespace through2 { /** * Convenvience method for creating object streams */ - export function obj(transform?: TransformFunction, flush?: FlushCallback): stream.Transform; + function obj(transform?: TransformFunction, flush?: FlushCallback): stream.Transform; /** * Creates a constructor for a custom Transform. This is useful when you * want to use the same transform logic in multiple instances. */ - export function ctor(opts?: stream.DuplexOptions, transfrom?: TransformFunction, flush?: FlushCallback): Through2Constructor; + function ctor(transform?: TransformFunction, flush?: FlushCallback): Through2Constructor; + function ctor(opts?: stream.DuplexOptions, transform?: TransformFunction, flush?: FlushCallback): Through2Constructor; } export = through2; diff --git a/types/through2/through2-tests.ts b/types/through2/through2-tests.ts index 70a66e4b0e..e1de34f3a9 100644 --- a/types/through2/through2-tests.ts +++ b/types/through2/through2-tests.ts @@ -4,6 +4,8 @@ import through2 = require('through2'); var rws: stream.Transform; var Rws: through2.Through2Constructor; +rws = through2(); + rws = through2({ objectMode: true, allowHalfOpen: true @@ -21,6 +23,14 @@ rws = through2(function (entry: any, enc: string, callback: () => void) { }); +rws = through2(function (entry, enc, callback) { + var str: string = enc; + this.push(entry, str); + callback(null, 'continue'); +}, () => { + +}); + rws = through2(function (entry: any, enc: string, callback: (error: any, data?: any) => void) { callback(null, 'foo'); }, (flushCallback: () => void) => { @@ -30,10 +40,10 @@ rws = through2(function (entry: any, enc: string, callback: (error: any, data?: rws = through2(function (entry: any, enc: string, callback: () => void) { this.push('foo'); callback(); +}, (flushCallback) => { + flushCallback(); }); -rws = through2(); - // obj rws = through2.obj(function (entry: any, enc: string, callback: () => void) { this.push('foo'); @@ -42,9 +52,10 @@ rws = through2.obj(function (entry: any, enc: string, callback: () => void) { }); -rws = through2.obj(function (entry: any, enc: string, callback: () => void) { - this.push('foo'); - callback(); +rws = through2.obj(function (entry, enc, callback) { + var str: string = enc; + this.push('foo', enc); + callback(null, entry); }); rws = through2.obj(function (entry: any, enc: string, callback: (err: any) => void) { @@ -68,7 +79,7 @@ rws = Rws(); rws = new Rws(); rws = new Rws({ objectMode: true, allowHalfOpen: true }); -Rws = through2.ctor(function (entry: any, enc: string, callback: () => void) { +Rws = through2.ctor(function (entry, enc, callback) { this.push('foo'); callback(); }, () => { @@ -80,8 +91,9 @@ rws = new Rws(); rws = new Rws({ objectMode: true, allowHalfOpen: true }); Rws = through2.ctor(function (entry: any, enc: string, callback: (error: any, data?: any) => void) { + this.emit("data", "more data"); callback(null, 'foo'); -}, (flushCallback: () => void) => { +}, (flushCallback) => { flushCallback(); }); @@ -93,7 +105,3 @@ Rws = through2.ctor(function (entry: any, enc: string, callback: () => void) { this.push('foo'); callback(); }); - -rws = Rws(); -rws = new Rws(); -rws = new Rws({ objectMode: true, allowHalfOpen: true });