2016-02-12 88 views
3

我已经使用JSPM和SystemJS设置了我的Angular2项目。我尝试在我的boot.ts文件中导入RxJS和几个运算符,但是我的导入不会被转储到boot.js输出中。所以为什么tsc(Typescript编译器)忽略RxJS导入?

// boot.ts 
import {Observable} from 'rxjs/Observable' 
import 'rxjs/add/operator/debounceTime' 
... 

如下概括:https://github.com/ReactiveX/RxJS#es6-via-npm最终成为

// boot.js 
System.register(['rxjs/add/operator/debounceTime', ... 

tsc(试图与1.7.5和1.8.0):

// tsconfig.json 
{ 
    "compilerOptions": { 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": true, 
    "noImplicitAny": false, 
    "module": "system", 
    "moduleResolution": "node", 
    "rootDir": "src", 
    "target": "es5" 
    } 

    , "exclude": [ 
    "jspm_packages", 
    "node_modules", 
    "typings/main.d.ts", 
    "typings/main" 
    ] 
} 

我在想什么???

UPDATE

打字稿只会emit进口如果在后面的代码中使用。我只需要额外的操作员来收听可以观察到的Angular2 controlvalueChanges。但是,如果Observable类的rxjs缺失,则不能修补其他运营商。让你有种需要通过导入这样的强制打字稿到emitSystem.registerObservable

// boot.ts 
import 'rxjs/Observable' 
import 'rxjs/add/operator/debounceTime' 
... 

一切归功于@RyanCavanaugh谁指出我到正确的方向。

+2

请参阅https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-imports-being-elided-in-my-emit –

+0

感谢您的快速回复'import'rxjs/Observable''完成了这项工作。 – TylerDurden

回答

0

你需要输入可观察的类的正确方法:

import { Observable } from 'rxjs/Observable'; 

或者,如果你想在同一时间所有的运营商如下:

import { Observable } from 'rxjs/Rx'; 
+0

我试过了,但没有任何区别。问题是 - 正如维基中所概述的那样 - 我后来在代码中没有使用'Observable',因为我只是将运算符应用于Angular控件的'valueChanges'观察值。无论如何感谢您的回答。 – TylerDurden