'unknown[]' 类型的参数不可分配给 > 'OperatorFunction 类型的参数

Sam*_*ath 11 rxjs typescript angularfire ionic-framework angular

组件.ts

initialize()方法说

“unknown[]”类型的参数不可分配给“OperatorFunction<unknown[],unknown>”类型的参数。类型“unknown[]”与签名“(source: Observable<unknown[]>): Observable”不匹配

alertsChanged$: Observable<AlertModel[]>;

private initialize(): void {
  

    this.alertsChanged$ = this.alertsService.getAlerts().pipe(
      map((res) => res), // here it returns the above error
      tap((res) => {
        
        this.setDataForFilters(res); //Argument of type 'unknown' is not assignable to parameter of type 'AlertModel[]'.  
       
      }),          
    );
  }

 private setDataForFilters(alerts: AlertModel[]): void {}
Run Code Online (Sandbox Code Playgroud)

服务.ts

 // no issues here

 getAlerts(): Observable<AlertModel[]> {
      return this.angularFireDatabase
      .list<AlertModel>(`groups/${this.groupId}/alerts`)
      .valueChanges()
      .pipe(
        map((res) => orderBy(res, ['timeStamp'], ['desc'])),
        first()
      );
  }
Run Code Online (Sandbox Code Playgroud)

.html

 <app-alerts
    [alerts]="alertsChanged$ | async"
  ></app-alerts>
Run Code Online (Sandbox Code Playgroud)

请让我把问题放在这里?

Sam*_*ath 25

我在这里发现了这个问题。Lodash map这是与和 的冲突RxJS map。即 VS code 由于 Lodash 映射而未导入 RxJS 映射,因此出现上述错误。

由于我需要在同一个组件上使用两者,所以我就这样做了。

import { finalize, tap, map } from 'rxjs/operators';

import { map as lodashMap } from 'lodash';
Run Code Online (Sandbox Code Playgroud)