【问题标题】:Property 'map' does not exist on type 'Observable<[{}, {}]>''Observable<[{}, {}]>' 类型上不存在属性 'map'
【发布时间】:2019-01-31 03:03:03
【问题描述】:

我正在尝试在 Angular6 中实现地图、PublishReplay 等,但每次它都会给我编译错误,说“属性 'map' 在类型 'Observable' 上不存在”。当我应用其他 rxjs 东西时也会发生类似情况。

我试过了

导入地图,安装rxjs-compat,编辑tsconfig.json

  unifiedSearch: Function = (query: string): Observable<UnifiedSearch> => {
    return forkJoin(
      this.searchService.gitSearch(query),
      this.codeSearchService.codeSearch(query)
    ).map((response :[GitSearch,GitCodeSearch])=> {
      return {
        respositories: response[0],
        code: response[1]
      };
    });
  };

如果我试图在“管道”的帮助下实现它,那么它会说我找不到地图。

 unifiedSearch: Function = (query: string): Observable<UnifiedSearch> => {
    return forkJoin(
      this.searchService.gitSearch(query),
      this.codeSearchService.codeSearch(query)
    ).pipe(map((response :[GitSearch,GitCodeSearch])=> {
      return {
        respositories: response[0],
        code: response[1]
      };
    }));
  };

【问题讨论】:

    标签: angular typescript observable


    【解决方案1】:

    确保你像这样导入地图 -

    import { map } from 'rxjs/operators';
    

    也可以使用管道。

    【讨论】:

    • 嗨,已经尝试过这样做,但它不起作用。管道说,地图没有找到属性。
    猜你喜欢
    • 2016-09-09
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2019-04-11
    相关资源
    最近更新 更多