mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-25 08:06:22 +08:00
highland: add the definition for the new isNil() for type guarding
This commit add the definition for the a very simple, and yet essential, isNil
function for type checking. This function is particularly useful in a consume
handler.
Example:
```
source.consume(function (err, x, push, next) {
if (err) {
// pass errors along the stream and consume next value
push(err);
next();
} else if (_.isNil(x)) { // type guard is only possible with this function
// pass nil (end event) along the stream
push(null, x);
} else {
// pass on the value only if the value passes the predicate
if (f(x)) {
push(null, x);
}
next();
}
});
```
See https://github.com/caolan/highland/pull/645
This commit is contained in:
11
types/highland/index.d.ts
vendored
11
types/highland/index.d.ts
vendored
@@ -89,6 +89,17 @@ interface HighlandStatic {
|
||||
// UTILS
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/**
|
||||
* Returns true if `x` is the end of stream marker.
|
||||
*
|
||||
* @id isNil
|
||||
* @section Streams
|
||||
* @name _.isNil(x)
|
||||
* @param x - the object to test
|
||||
* @api public
|
||||
*/
|
||||
isNil<R>(x: R | Highland.Nil): x is Highland.Nil;
|
||||
|
||||
/**
|
||||
* Returns true if `x` is a Highland Stream.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user