Angular 2 beta.17:类型"Observable< Response>"上不存在属性"map" [英] Angular 2 beta.17: Property 'map' does not exist on type 'Observable<Response>'

查看:77
本文介绍了Angular 2 beta.17:类型"Observable< Response>"上不存在属性"map"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从Angular 2 beta16 升级到了 beta17 ,这反过来又需要rxjs 5.0.0-beta.6. (此处的更改日志: https://github .com/angular/angular/blob/master/CHANGELOG.md#200-beta17-2016-04-28 )在beta16中,关于Observable/map功能,一切运行良好.升级后出现以下错误,当打字稿尝试转换时会发生以下错误:

I just upgraded from Angular 2 beta16 to beta17, which in turn requires rxjs 5.0.0-beta.6. (Changelog here: https://github.com/angular/angular/blob/master/CHANGELOG.md#200-beta17-2016-04-28) In beta16 all was working well regarding Observable/map functionality. The following errors appeared after I upgraded and occur when typescript attempts to transpile:

  1. 可观察"类型(在我将地图与可观察性结合使用的任何地方)都不存在属性地图"
  2. c:/path/node_modules/rxjs/add/operator/map.d.ts(2,16):错误TS2435:环境模块不能嵌套在其他模块或命名空间中.
  3. c:/path/node_modules/rxjs/add/operator/map.d.ts(2,16):错误TS2436:环境模块声明无法指定相对模块名称.
  1. Property 'map' does not exist on type 'Observable' (anywhere where I've used map with an observable)
  2. c:/path/node_modules/rxjs/add/operator/map.d.ts(2,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces.
  3. c:/path/node_modules/rxjs/add/operator/map.d.ts(2,16): error TS2436: Ambient module declaration cannot specify a relative module name.

我已经看到了这个问题/答案,但不能解决问题: Angular2 beta.12和RxJs 5 beta的可观察到的错误. 3

I have seen this question/answer but it does not solve the problem: Observable errors with Angular2 beta.12 and RxJs 5 beta.3

我的appBoot.ts看起来像这样(已经引用rxjs/map了):

My appBoot.ts looks like this (am already referencing rxjs/map):

///<reference path="./../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from "angular2/platform/browser";
import {ROUTER_PROVIDERS} from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';
[stuff]
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import {enableProdMode} from 'angular2/core';
import { Title } from 'angular2/platform/browser';


//enableProdMode();
bootstrap(AppDesktopComponent, [
    ROUTER_PROVIDERS,
    HTTP_PROVIDERS,
    Title
]);

有人有什么想法吗?

推荐答案

我将gulp-typescript插件升级到了最新版本(2.13.0),现在可以正常编译了.

I upgraded my gulp-typescript plugin to the latest version (2.13.0) and now it compiles without hitch.

更新1:我以前使用的是gulp-typescript版本2.12.0

UPDATE 1: I was previously using gulp-typescript version 2.12.0

更新2:如果要升级到Angular 2.0.0-rc.1,则需要在appBoot.ts文件中执行以下操作:

UPDATE 2: If you are upgrading to the Angular 2.0.0-rc.1, you need to do the following in your appBoot.ts file:

///<reference path="./../typings/browser/ambient/es6-shim/index.d.ts"/>
import { bootstrap } from "@angular/platform-browser-dynamic";
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
import { HTTP_PROVIDERS } from '@angular/http';
import { AppComponent } from "./path/AppComponent";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
// import 'rxjs/Rx'; this will load all features
import { enableProdMode } from '@angular/core';
import { Title } from '@angular/platform-browser';



//enableProdMode();
bootstrap(AppComponent, [
    ROUTER_PROVIDERS,
    HTTP_PROVIDERS,
    Title
]);

重要的是对es6-shim/index.d.ts的引用

The important thing being the reference to es6-shim/index.d.ts

这假设您已经安装了es6-shim类型,如下所示:

This assumes you have installed the es6-shim typings as shown here:

有关从Angular安装的更多打字信息,请参见: https://angular. io/docs/ts/latest/guide/typescript-configuration.html#!#typings

More on the typings install from Angular here: https://angular.io/docs/ts/latest/guide/typescript-configuration.html#!#typings

这篇关于Angular 2 beta.17:类型"Observable&lt; Response&gt;"上不存在属性"map"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆