0
我搜索了很多,試圖看d.ts文件,但仍然不明白什麼是錯的。找不到RxJs5如何使用此功能的示例。如何使用RxJS 5緩衝區功能?
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:類型的參數「()=>可觀察< {}>不是分配給類型 '可觀測' 的參數。 類型'()=>可觀察< {}>'中缺少屬性'_isScalar'。
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[]>;
}
這個問題從這個傳來: Counting keypresses per second with angular 2 Rxjs
你傳遞一個功能,但你應該通過可觀察。 –