Mat*_*att 1 javascript observable rxjs typescript
我正在尝试观察流中发生的最新事件。每个事件可以是两种类型之一,由枚举表示。但是,我在以下示例中收到编译错误:
import { BehaviorSubject } from 'rxjs/Rx';
export enum FilterAction {
RESET, UPDATE
}
export class FilterSomething {
private _filterEvent: BehaviorSubject<FilterAction> = new BehaviorSubject(FilterAction.RESET);
get filterEvent() {
return this._filterEvent.asObservable(); // <-- behave.ts(14,12): error TS2322: Type 'Observable<FilterAction>' is not assignable to type 'FilterAction'
}
set filterEvent(action: FilterAction){
this._filterEvent.next(action);
}
}
Run Code Online (Sandbox Code Playgroud)
编译错误:
behave.ts(14,12): error TS2322: Type 'Observable<FilterAction>' is not assignable to type 'FilterAction'
然而,当我使用通用any
它编译(并工作)。
set filterEvent(filterAction: any) {
this._filterEvent.next(filterAction);
}
Run Code Online (Sandbox Code Playgroud)
我怀疑这与枚举值有关,而不是与FilterAction
.
归档时间: |
|
查看次数: |
3512 次 |
最近记录: |