使用beta6编译错误

时间:2016-05-03 19:43:58

标签: angular rxjs rxjs5

使用rxjs beta2我的项目效果很好,但是更新到beta6我得到了很长的编译错误列表:

component.ts(34,18): error TS2339: Property 'finally' does not exist on type 'Observable<T[]>'.
....
....
.component.ts(51,10): error TS2339: Property 'switchMap' does not exist on type 'Observable<Company>'.
....
....
service.ts(24,18): error TS2339: Property 'map' does not exist on type 'Observable<Response>'
....
....
node_modules/rxjs/add/observable/range.d.ts(2,16): error TS2435: Ambient modules cannot be nested in other modules.
node_modules/rxjs/add/observable/range.d.ts(2,16): error TS2436: Ambient module declaration cannot specify relative module name.
node_modules/rxjs/add/operator/catch.d.ts(2,16): error TS2435: Ambient modules cannot be nested in other modules.
node_modules/rxjs/add/operator/catch.d.ts(2,16): error TS2436: Ambient module declaration cannot specify relative m
..

我正在导入这样的Observable:

import {Observable} from 'rxjs/Observable';

我做错了什么?

非常感谢

修改 使用rc1 rxjs beta6的作品。 但是我必须把结果投射到我所有的可观测量上。 在我使用之前:

this._couseSourcesSvc.readAll ()
    .finally (() => sourcesSpinner.hide ())
    .subscribe (
        res => {
            this.sources = res;
        }

但现在我必须使用:

this._couseSourcesSvc.readAll ()
    .finally (() => sourcesSpinner.hide ())
    .subscribe (
        (res:Sources[]) => {
            this.sources = res;
        }

正如您所看到的,我必须转换结果,否则会出现编译错误 (RES:来源[])

Type '{}' is not assignable to type 'DocumentSource[]'.

这是正常的吗?

2 个答案:

答案 0 :(得分:2)

只有Angular2 rc.0(刚刚在昨晚发布)支持rx beta 6。

升级你的角度以释放候选人1以便能够更新RxJs。

  

请注意,您必须将导入更新为@angular/core | @angular/http等。名称已从angular2/*

更改

答案 1 :(得分:2)

如果您想拥有运营商,则需要导入它们:

import {Observable} from 'rxjs/Rx';

或按操作员:

import {Observable} from 'rxjs/add/operator/switchMap';
相关问题