我想要遵循RxJS的说明:
https://rxjs-dev.firebaseapp.com/guide/installation
我执行以下操作
cd
并调用npm init
,将所有默认值用于npm import Rx from 'rxjs/Rx';
test.tstsc test.ts
我收到一条错误消息:
node_modules/rxjs/internal/Observable.d.ts:82:59 - error TS2693: 'Promise' only refers to a type, but is being used as a value here.
82 toPromise<T>(this: Observable<T>, PromiseCtor: typeof Promise): Promise<T>;
~~~~~~~
如何正确地做到这一点?
评论后编辑:
在Introduction page上还提到了另一个示例:
const { fromEvent } = rxjs;
const button = document.querySelector('button');
fromEvent(button, 'click')
.subscribe(() => console.log('Clicked!'));
这不能是要提供给tsc
的完整文件。我得到了错误消息:
fl.ts:1:23 - error TS2304: Cannot find name 'rxjs'.
1 const { fromEvent } = rxjs;
~~~~
同样,在添加import 'rxjs'
之后,仍然会出现相同的错误消息。如何填写该文件?
发布于 2018-07-26 02:52:13
您必须创建包含以下选项的tsconfig.json
文件:
{
"compilerOptions": {
"target": "es5",
"lib": ["es2015", "dom"]
}
}
在此之后,您可以简单地在终端中运行tsc
(没有文件名)。它将在可以使用node test.js
执行的同一目录中创建一个test.js
文件。
我的test.ts文件如下所示:
import { of } from 'rxjs';
const source = of('demo value');
source.subscribe(value => {
console.log(value);
});
https://stackoverflow.com/questions/51524506
复制相似问题