Why does tsc (Typescript Compiler) ignore RxJS import?

时间:2016-02-12 21:56:11

标签: typescript angular rxjs systemjs jspm

I have setup my Angular2 project using JSPM and SystemJS. I try to import $.post({ url: 'process.php', data: { ......., X: 1} }); and a few operators in my RxJS file but my import does NOT get transpiled into the boot.ts output. So

boot.js

as outlined here: https://github.com/ReactiveX/RxJS#es6-via-npm ends up as

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

// boot.js System.register(['rxjs/add/operator/debounceTime', ... (tried with 1.7.5 and 1.8.0):

tsc

What am I missing???

UPDATE

TypeScript will only // 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" ] } the import if it is used later in the code. I just needed the additional operators to listen to a emit observable to an Angular2 valueChanges. However, the additional operators cannot be patched if the control class of Observable is missing. So you kind of need to force TypeScript to rxjs the emit for System.register by importing like this:

Observable

All credit goes to @RyanCavanaugh who pointed me into the right direction.

2 个答案:

答案 0 :(得分:1)

评论的答案,成功解决了问题:

import 'rxjs/Observable'

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

答案 1 :(得分:0)

您需要以正确的方式导入Observable类:

import { Observable } from 'rxjs/Observable';

如果您想在同一时间包含所有运算符,请执行以下操作:

import { Observable } from 'rxjs/Rx';