2017-05-24 114 views
0

最近,当我用Rxjs 5,我下载Rxjs使用NPM安装[email protected],从下node_modules下载的代码,我发现Observable.d.ts在Rxjs文件夹中,我看到了它的声明构造象下面这样:此关键字的功能参数

* 
* @constructor 
* @param {Function} subscribe the function that is called when the Observable is 
* initially subscribed to. This function is given a Subscriber, to which new values 
* can be `next`ed, or an `error` method can be called to raise an error, or 
* `complete` can be called to notify of a successful completion. 
*/ 
constructor(subscribe?: <R>(this: Observable<T>, subscriber: Subscriber<R>) => TeardownLogic); 

我的问题是:这是什么关键字的订阅?:函数类型声明的使用(这一点:观察的,...),是否有打字原稿这个关键字的使用像一些文档这里?谢谢。

回答

1

你可以(因为打字稿的2.0版本)规定什么是this被调用的函数,当你期待。

Specifying the type of this for functions描述:

上指定的这类或类型的 接口跟进,函数和方法现在可以声明的这一点,他们 期望的类型。

默认情况下,这个函数里面的类型是任何。从 开始TypeScript 2.0,你可以提供一个明确的这个参数。这 参数是放在第一位的功能

注意,这将不会翻译成JS的参数列表 假的参数,所以它不是功能的真正理由。

+0

谢谢你,帮我找到文档。 – IcyBrk