且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

输入“可观察的"缺少类型“Observable<>"中的以下属性:[见下文](错误 TS2322)

更新时间:2022-02-19 08:51:43

我想我可以找到解决方案.我在我的项目中与 rxjs 导入有冲突.在故障排除过程中.我发现编译器试图比较来自两个不同版本(以及不同目录中)的两个 rxjs 对象.

Edit : I think that I could find a solution. I had a conflict with rxjs imports in my project. During the troubleshooting. I found out that the compiler was trying to compare two rxjs objects from two different versions (and in different directories).

我从我的主目录中卸载了 rxjsrxjs-compat 以仅使用项目文件夹中的那些.

I uninstalled the rxjs and rxjs-compat from my home directory to used then only the ones in the project folder.

为了摆脱 rxjs/Rx,正如 JB Nizet 所说,我只使用了以下两个导入:

To get away with rxjs/Rx, as JB Nizet said, I used only the two following imports :

  • import { Observable } from 'rxjs';
  • import 'rxjs/add/observable/of';

(告诉我是否有办法做得更好,不知何故)

(Tell me if there is a way to do it better, somehow)