管道运算符不受支持:Angular [Typescript]-rxjs-CombineLatest 从❤Ingo Burk

带有问题的代码

import { Injectable } from '@angular/core';
import { accountingTransactionsStoreService } from './accounting-transactions-store.service';
import { GeneralLedgeraccountsStoreService } from './general-ledger-accounts-store.service';
import { distinctUntilChanged,map,combineLatest } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class accountingReportsStoreService {


  constructor(
    private accountingTransactionsStore: accountingTransactionsStoreService,private   generalLedgeraccountsStore: GeneralLedgeraccountsStoreService) 
    {}

  readonly generalLedgeraccountsTransaction$
    = combineLatest(
      this.accountingTransactionsStore.selectedPeriodaccountingTransactionsflate$,this.generalLedgeraccountsStore.selectedOrganizationGeneralLedgeraccountsTree$)
      .pipe(distinctUntilChanged())
      .pipe(
        map(([transactionsflat,accountsTree]) => {
          if (transactionsflat && accountsTree)
            return [];
          else return [];
        })
      )
}

错误

  

类型'OperatorFunction '。

wuzongzhi 回答:管道运算符不受支持:Angular [Typescript]-rxjs-CombineLatest 从❤Ingo Burk

怎么了?

import { distinctUntilChanged,map,combineLatest } from 'rxjs/operators';

为什么?

实际上不确定,但是我看起来是关于功能定义超载

从❤Ingo Burk

更新
  

combineLatest作为操作符和函数存在于彼此之间。但是,不建议使用操作员版本。根据导入,您会得到一个。

解决方法

'rxjs' 导入 combineLatest ,而不从 'rxjs / operators'导入

import { distinctUntilChanged,map } from 'rxjs/operators';
import { combineLatest} from 'rxjs';

我是如何找到解决方案的?

  • 删除了rxjs导入
  • 使用过的vscode 添加所有丢失的导入内容 (偶然发现(我反复尝试))
  • enter image description here

我学到了什么?有模式吗?

  • 是,不是,这不是一种模式,而是一个把戏!?‍♀️
  • 尝试删除进口商品
  • 并使用 添加所有缺少的进口商品
  • 然后让 VSCode 决定要导入的内容
  • 然后观察差异
  • 然后用我的判断力
  • 因为 VSCode 比我对我的代码有更多的了解knowledge‍♀️
本文链接:https://www.f2er.com/3126327.html

大家都在问