如何为 highlandjs 键入提示 Stream of Streams?
How to typehint Stream of Streams for highlandjs?
我正在使用 typescript@2 和 highlandjs 库。 highland 的类型缺少 mergeWithLimit(n)
函数。它:
Takes a Stream of Streams and merges their values and errors into a
single new Stream, limitting the number of unpaused streams that can
running at any one time.
现在,此方法还没有对其 DefinitlyTyped typings 进行类型提示。我试图添加它,但是对于流的流只有 interface Stream<R>
和 none。
然而,我如何为流的流创建接口?我尝试定义一个接口:
interface Stream<Stream<R>> implements Stream<R> {
mergeWithLimit(n: number): Stream<R>;
}
但它没有编译:
365 interface Stream<Stream<R>> implements Stream<R> {
~
index.d.ts(365,28): error TS1005: ',' expected.
365 interface Stream<Stream<R>> implements Stream<R> {
~
index.d.ts(365,31): error TS1109: Expression expected.
365 interface Stream<Stream<R>> implements Stream<R> {
~~~~~~
index.d.ts(365,44): error TS1005: ';' expected.
如何正确输入提示 mergeWithLimit
?
我们通过定义接口来正确管理类型提示:
interface StreamOfStreams<R> extends Stream<Stream<R>> {
/**
* Takes a Stream of Streams and merges their values and errors into a single new Stream,
* limitting the number of unpaused streams that can running at any one time.
*
* @id mergeWithLimit
* @section Streams
* @name Stream.mergeWithLimit()
* @api public
*/
mergeWithLimit(n: number): Stream<R>;
}
并且我们添加了地图定义:
interface Stream<R> extends NodeJS.EventEmitter {
map<U>(f: (x: R) => U): Stream<U>;
map<S>(f: (x: R) => Stream<S>): StreamOfStreams<S>;
}
现在我们可以通过以下方式正确输入提示 mergeWithLimit(n)
:
myStream.map<YourType>(whatEverTheMapFunction).mergeWithLimit(10)
我正在使用 typescript@2 和 highlandjs 库。 highland 的类型缺少 mergeWithLimit(n)
函数。它:
Takes a Stream of Streams and merges their values and errors into a single new Stream, limitting the number of unpaused streams that can running at any one time.
现在,此方法还没有对其 DefinitlyTyped typings 进行类型提示。我试图添加它,但是对于流的流只有 interface Stream<R>
和 none。
然而,我如何为流的流创建接口?我尝试定义一个接口:
interface Stream<Stream<R>> implements Stream<R> {
mergeWithLimit(n: number): Stream<R>;
}
但它没有编译:
365 interface Stream<Stream<R>> implements Stream<R> {
~
index.d.ts(365,28): error TS1005: ',' expected.
365 interface Stream<Stream<R>> implements Stream<R> {
~
index.d.ts(365,31): error TS1109: Expression expected.
365 interface Stream<Stream<R>> implements Stream<R> {
~~~~~~
index.d.ts(365,44): error TS1005: ';' expected.
如何正确输入提示 mergeWithLimit
?
我们通过定义接口来正确管理类型提示:
interface StreamOfStreams<R> extends Stream<Stream<R>> {
/**
* Takes a Stream of Streams and merges their values and errors into a single new Stream,
* limitting the number of unpaused streams that can running at any one time.
*
* @id mergeWithLimit
* @section Streams
* @name Stream.mergeWithLimit()
* @api public
*/
mergeWithLimit(n: number): Stream<R>;
}
并且我们添加了地图定义:
interface Stream<R> extends NodeJS.EventEmitter {
map<U>(f: (x: R) => U): Stream<U>;
map<S>(f: (x: R) => Stream<S>): StreamOfStreams<S>;
}
现在我们可以通过以下方式正确输入提示 mergeWithLimit(n)
:
myStream.map<YourType>(whatEverTheMapFunction).mergeWithLimit(10)