首页 文章

Angular 6 ng lint combineLatest已弃用

提问于
浏览
9

我最近从Angular 5更新到Angular 6 .

我收到了这个警告 combineLatest is deprecated: resultSelector no longer supported, pipe to map instead . Rxjs是版本6.1.0,tslint是5.10.0,Angular CLI是6.0.0和Typescript 2.7.2 . 我这样使用它:

const a$ = combineLatest(
  this.aStore.select(b.getAuth),
  this.cStore.select(b.getUrl),
  (auth, url) => ({auth, url}),
);

我也尝试过这样:

empty().pipe(
combineLatest(...),
  ...
)

但这给了我: combineLatest is deprecated: Deprecated in favor of static combineLatest 和empty也被弃用,而不是静态版本 .

4 回答

  • 0

    不推荐使用combineLatest:不再支持resultSelector,而是管道映射

    上面的警告建议删除resultSelector你在combineLatest observable中提供的最后一个函数,并将其作为map运算符的一部分提供,如下所示

    const a$ = combineLatest(
      this.aStore.select(b.getAuth),
      this.cStore.select(b.getUrl)
    );
    
    const result$ = a$.pipe(
      map(results => ({auth: results[0], url: results[1]}))
    )
    
  • 26

    对于 trailing comma 错误,请删除 (auth, url) => ({auth, url}) 之后的逗号

    const a$ = combineLatest(
      this.aStore.select(b.getAuth),
      this.cStore.select(b.getUrl),
      (auth, url) => ({auth, url}),  // Remove this comma.
    );
    

    对于 missing import 错误,请确保您具有文件中正在使用的所有外部var或类的导入 .

    例如,在这种情况下,如果您还没有导入 combineLatest ,则导入它

    import { combineLatest } from 'rxjs'; // For RxJS 6.x
    
    import { combineLatest } from 'rxjs/operators'; // For RxJS 5.x
    
  • 1

    linting错误的答案:

    combineLatest已弃用:不赞成使用static combineLatest

    可以在这个stackoverflow问题中找到:

    combineLatest is deprecated: Deprecated in favor of static combineLatest

  • 1

    不幸的是,如果从运算符导入combineLatest,也可能会出现tslint错误:

    import { combineLatest } from 'rxjs/operators';
    
    combineLatest(...array);
    

    代替,

    import { combineLatest } from 'rxjs';
    
    combineLatest(...array);
    

相关问题