TS1148~如何使用--module:"none"和typescricpt 2.x"导入"

J.D*_*Doe 5 javascript browser typescript typescript2.0

我目前正在开发一个包含一些javascript遗留代码的项目.该应用程序不包含模块加载器,它只是将所有内容作为全局放入窗口对象中.触摸遗留代码并包含模块加载器对我来说遗憾的是不可行.

我想使用typescript作为我自己的代码,因此我确实设置了typescript compiler-option

module : "none"
Run Code Online (Sandbox Code Playgroud)

在我的tsconfig.json中,我只使用命名空间来组织我自己的代码.到目前为止工作得很好.

.. 到现在:

import * as Rx from 'rxjs';
..
Rx.Observable.from(['foo',bar']);
...
// Results in TypeScript-Error: 
//   TS1148:Cannot use imports, exports, or module augmentations when '--module' is 'none'. 
Run Code Online (Sandbox Code Playgroud)

如果设置了"module-none"选项,则不能在打字稿中使用import语句.
如何在这个打字稿设置中包含外部库?
它甚至可能吗?

到目前为止我尝试了什么(包括来自RxJs-Library的Rx)

///<reference path="../node_modules/rxjs/Rx.d.ts" />
..
Rx.Observable.from(['foo',bar']);
...
// Results in TypeScript-Error -> TS2304:Cannot find name 'Rx'. 
Run Code Online (Sandbox Code Playgroud)

在这个相关问题中,Kirill Dmitrenko使用参考标签消化,对我不起作用.

我最终得到了这个结构.

declare const Rx: any;
Run Code Online (Sandbox Code Playgroud)

工作,但你松散的类型检查和intellisense :(

ode*_*nsc 5

创建一个全局声明,Rx该声明是RxJS导出的类型,如下所示:

import * as RxJS from "rxjs";

declare global {
    const Rx: typeof RxJS;
}

export {};
Run Code Online (Sandbox Code Playgroud)

将其保存到文件(例如global.d.ts),然后将其添加到的include数组中tsconfig.json