首页 文章

为什么tsc(Typescript Compiler)会忽略RxJS导入?

提问于
浏览
3

我使用JSPM和SystemJS设置了我的Angular2项目 . 我尝试在我的 boot.ts 文件中导入 RxJS 和一些运算符,但我的导入不会被转换为 boot.js 输出 . 所以

// 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

如果稍后在代码中使用TypeScript,则TypeScript将仅导入 emit . 我只需要额外的运算符来监听Angular2 controlvalueChanges observable . 但是,如果缺少 rxjsObservable 类,则无法修补其他运算符 . 所以你需要通过这样的导入强制TypeScript到 emit System.register for Observable

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

所有的功劳归功于@RyanCavanaugh,他指出了我正确的方向 .

2 回答

相关问题