我正在使用typescript @ 2和highlandjs库。高地的打字错过mergeWithLimit(n)
功能。它:
采用Streams流并将其值和错误合并为一个 单个新流,限制可以使用的未流量流的数量 任何时候都在跑。
现在,此方法尚未为其DefinitlyTyped typings打字。我试图添加它,但是只有一个interface Stream<R>
而没有一个流流。
然而,我如何为流媒体流创建界面?我尝试定义一个接口:
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
?
答案 0 :(得分:0)
We managed typehint it correctly by defining an interface:
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>;
}
and we added a map defintion:
interface Stream<R> extends NodeJS.EventEmitter {
map<U>(f: (x: R) => U): Stream<U>;
map<S>(f: (x: R) => Stream<S>): StreamOfStreams<S>;
}
This now allows us to correctly typehint mergeWithLimit(n)
by usage of:
myStream.map<YourType>(whatEverTheMapFunction).mergeWithLimit(10)