flatting Observable of Array to Observable of items

时间:2017-03-15 12:23:27

标签: angular typescript rxjs

我试图将Observable<Array<ISource>>展平为Observable<ISource>

为了得到它:

this.sources$ = this.store$
    .select(fromRoot.getSourceEntities)
    .map(sourceEntities => {
      return sourceEntities
        .filter((source:ISource) => source.id != null)
        .map((source:ISource) => { return <ISource>{id: source.id}; });
    })
    .takeUntil(this.componentDestroyed$);

我收到此编译器错误消息:

Type 'Observable<ISource[]>' is not assignable to type 'Observable<ISource>'.

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

this.sources$ISource的类型,但您要向其返回ISource[],这就是为什么它会将this.sources$的更改改为sourceEntries以下的sources$: ISource[]; 是一个数组,它是过滤器并返回一堆ISource对象。

if (FTP::connection()->changeDir('directory-name')->makeDir('sub-directory')) {
    echo "directory made";
}
相关问题