我google了很多,试着看看d.ts文件,但仍然无法理解有什么问题。找不到RxJs5的例子如何使用这个函数。
var source = Observable.fromEvent(document.body, 'keypress');
var delayedSource = source.delay(1000);
var obs = source
.buffer(() => {
return delayedSource;
})
.map((clickBuffer) => {
return clickBuffer.length;
});
我收到错误:
错误:(166,15)TS2345:类型'()=>的参数可观察到的与LT; {}>”不能分配给'Observable'类型的参数。 '()=>类型中缺少属性'_isScalar'可观察到的与LT; {}>”
buffer.d.ts看起来这个,我想我应该从中理解,但我不能。
import { Observable } from '../Observable';
/**
* Buffers the incoming observable values until the passed `closingNotifier`
* emits a value, at which point it emits the buffer on the returned observable
* and starts a new buffer internally, awaiting the next time `closingNotifier`
* emits.
*
* <img src="./img/buffer.png" width="100%">
*
* @param {Observable<any>} closingNotifier an Observable that signals the
* buffer to be emitted} from the returned observable.
* @returns {Observable<T[]>} an Observable of buffers, which are arrays of
* values.
*/
export declare function buffer<T>(closingNotifier: Observable<any>): Observable<T[]>;
export interface BufferSignature<T> {
(closingNotifier: Observable<any>): Observable<T[]>;
}
答案 0 :(得分:0)
基于Benjamin Gruenbaum的评论,这解决了这个问题:
var source = Observable.fromEvent(document.body, 'keypress');
var delayedSource = source.delay(1000);
var obs = source
.buffer(delayedSource)
.map((clickBuffer) => {
return clickBuffer.length;
})