From 11c5e219384bf4f68a008e1e4bf6f89bc803be2f Mon Sep 17 00:00:00 2001 From: TeamworkGuy2 Date: Fri, 12 May 2017 13:26:27 +0000 Subject: [PATCH 1/2] [through2] Add 'this' type to callbacks and fix through2.ctor() signature for optional 'options' parameter --- types/through2/index.d.ts | 19 +++++++++---------- types/through2/through2-tests.ts | 30 +++++++++++++++++++----------- types/through2/tslint.json | 3 +++ 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 types/through2/tslint.json 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 }); diff --git a/types/through2/tslint.json b/types/through2/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/through2/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file From 9e9a249600dc561a3645118304bfeb63a038e637 Mon Sep 17 00:00:00 2001 From: TeamworkGuy2 Date: Fri, 12 May 2017 13:54:45 +0000 Subject: [PATCH 2/2] [through2] remove tslint to fix test file build errors --- types/through2/tslint.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 types/through2/tslint.json diff --git a/types/through2/tslint.json b/types/through2/tslint.json deleted file mode 100644 index e60c15844f..0000000000 --- a/types/through2/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "dtslint/dt.json" -} \ No newline at end of file