From 81db85e6eef178cc114fc095cd068a9997ef810f Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 22 Feb 2018 19:12:00 +0000 Subject: [PATCH] fix(highland): correct the definition of consume The record variable should contain the type of Highland.Nil for it also takes the marker as a sign of the end of stream. See http://highlandjs.org/#consume --- types/highland/highland-tests.ts | 101 +++++++++++++++---------------- types/highland/index.d.ts | 2 +- 2 files changed, 49 insertions(+), 54 deletions(-) diff --git a/types/highland/highland-tests.ts b/types/highland/highland-tests.ts index e97c5c9416..5f1c734395 100644 --- a/types/highland/highland-tests.ts +++ b/types/highland/highland-tests.ts @@ -1,5 +1,3 @@ - - // Note: try to maintain the ordering and separators // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -49,18 +47,18 @@ var anyArrStream: Highland.Stream; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - interface Foo { - foo(): string; + foo(): string; } interface Bar { - bar(): string; + bar(): string; } interface StrFooArrMap { - [key:string]: Foo[]; + [key: string]: Foo[]; } interface StrBarArrMap { - [key:string]: Bar[]; + [key: string]: Bar[]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -128,9 +126,9 @@ fooStream = streamRedirect.to; fooStream = _(); fooStream = _(fooArr); fooStream = _((push, next) => { - push(null, foo); - push(err); - next(); + push(null, foo); + push(err); + next(); }); fooStream = _(fooStream); @@ -173,16 +171,23 @@ fooArrStream = fooStream.collect(); fooStream = fooStream.compact(); -barStream = fooStream.consume((err: Error, x: Foo, push: (err: Error, value?: Bar) => void, next: () => void) => { - push(err); - push(null, bar); - next(); -}); +barStream = fooStream.consume( + ( + err: Error, + x: Foo | Highland.Nil, + push: (err: Error, value?: Bar | Highland.Nil) => void, + next: () => void + ) => { + push(err); + push(null, bar); + next(); + } +); barStream = fooStream.consume((err, x, push, next) => { - push(err); - push(null, bar); - next(); + push(err); + push(null, bar); + next(); }); fooStream = fooStream.debounce(num); @@ -191,30 +196,32 @@ fooStream = fooStream.doto((x: Foo) => {}); fooStream = fooStream.drop(2); -fooStream = fooStream.errors((err: Error, push: (e: Error, x?: Foo) => void) => { - push(err); - push(null, x); - push(null, foo); -}); +fooStream = fooStream.errors( + (err: Error, push: (e: Error, x?: Foo) => void) => { + push(err); + push(null, x); + push(null, foo); + } +); fooStream = fooStream.errors((err, push) => { - push(err); - push(null, x); - push(null, foo); + push(err); + push(null, x); + push(null, foo); }); fooStream = fooStream.filter((x: Foo) => { - return bool; + return bool; }); fooStream = fooStream.find((x: Foo) => { - return bool; + return bool; }); fooStream = fooStream.findWhere(obj); strFooArrMapStream = fooStream.group((x: Foo) => { - return str; + return str; }); strFooArrMapStream = fooStream.group(str); @@ -227,7 +234,7 @@ fooStream = fooStream.last(); fooStream = fooStream.latest(); barStream = fooStream.map((x: Foo) => { - return bar; + return bar; }); barStream = fooStream.pluck(str); @@ -235,26 +242,24 @@ barStream = fooStream.pluck(str); fooStream = fooStream.ratelimit(3, 1000); barStream = fooStream.reduce(bar, (memo: Bar, x: Foo) => { - return memo; + return memo; }); barStream = fooStream.reduce1(bar, (memo: Bar, x: Foo) => { - return memo; + return memo; }); fooStream = fooStream.reject((x: Foo) => { - return bool; + return bool; }); barStream = fooStream.scan(bar, (memo: Bar, x: Foo) => { - return memo; + return memo; }); //missing scan1 -fooStream = fooStream.stopOnError((e: Error) => { - -}); +fooStream = fooStream.stopOnError((e: Error) => {}); fooStream = fooStream.take(num); @@ -264,7 +269,6 @@ fooStream = fooStream.throttle(num); fooStream = fooStream.where(obj); - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // HIGHER-ORDER STREAMS // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -274,15 +278,15 @@ fooStream = fooStream.concat(fooStream); fooStream = fooStream.concat(fooArr); fooStream = fooStream.flatFilter((x: Foo) => { - return boolStream; + return boolStream; }); barStream = fooStream.flatMap((x: Foo) => { - return barStream; + return barStream; }); barStream = fooStream.flatMap((x: Foo) => { - return bar; + return bar; }); barStream = fooStream.flatten(); @@ -315,24 +319,16 @@ fooStream.apply(func); fooStream.done(() => {}); -fooStream.each((x: Foo) => { - -}); +fooStream.each((x: Foo) => {}); fooStream = fooStream.pipe(fooStream); barStream = fooStream.pipe(barStream); -fooStream.pull((err: Error, x: Foo) => { +fooStream.pull((err: Error, x: Foo) => {}); -}); +fooStream.pull((err, x) => {}); -fooStream.pull((err, x) => { - -}); - -fooStream.toArray((arr: Foo[]) => { - -}); +fooStream.toArray((arr: Foo[]) => {}); fooStream.toCallback((err: Error, x: Foo) => {}); fooStream.toCallback((err: Error) => {}); @@ -360,7 +356,6 @@ f = _.wrapCallback(func, num); f = _.wrapCallback(func, strArr); f = _.wrapCallback(func, fn); - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // OBJECTS // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/types/highland/index.d.ts b/types/highland/index.d.ts index acfaadd6ea..eff8fb2769 100644 --- a/types/highland/index.d.ts +++ b/types/highland/index.d.ts @@ -563,7 +563,7 @@ declare namespace Highland { * @param {Function} f - the function to handle errors and values * @api public */ - consume(f: (err: Error, x: R, push: (err: Error | null, value?: U | Highland.Nil) => void, next: () => void) => void): Stream; + consume(f: (err: Error, x: R | Highland.Nil, push: (err: Error | null, value?: U | Highland.Nil) => void, next: () => void) => void): Stream; /** * Holds off pushing data events downstream until there has been no more