rxjs/Subject.d.ts error : Class 'Subject' incorrectly extends base class 'Observable'

前端 未结 19 2125
一向
一向 2020-12-01 09:55

I extracted sample template code from this tutorial and did below two steps to get started -

  1. npm install // worked fine and created node_modules folder
19条回答
  •  Happy的楠姐
    2020-12-01 10:28

    You can temporarily work around the issue by using Module Augmentation

    The following code resolved the issue for me. Once RxJS has a stable release that does not exhibit this issue, it should be removed.

    // augmentations.ts
    import {Operator} from 'rxjs/Operator';
    import {Observable} from 'rxjs/Observable';
    
    // TODO: Remove this when a stable release of RxJS without the bug is available.
    declare module 'rxjs/Subject' {
      interface Subject {
        lift(operator: Operator): Observable;
      }
    }
    

    While it is perhaps ironic that RxJS itself makes such heavy use of this technique to describe its own shape, it is actually generally applicable to an array of problems.

    While there are certainly limits and rough edges, part of what makes this technique powerful is that we can use it to enhance existing declarations making them more type safe without forking and maintain the entire file.

提交回复
热议问题