this keyword for function parameter

前端 未结 1 792
逝去的感伤
逝去的感伤 2021-01-05 19:28

Recently when I use Rxjs 5, I downloaded Rxjs by using npm install Rxjs@5.0.1, from downloaded code under node_modules, I found Observable.d.ts in Rxjs folder, I saw it decl

1条回答
  •  [愿得一人]
    2021-01-05 20:26

    You can (since version 2.0 of typescript) specify what is the this you're expecting when a function is invoked.

    As described in Specifying the type of this for functions:

    Following up on specifying the type of this in a class or an interface, functions and methods can now declare the type of this they expect.

    By default the type of this inside a function is any. Starting with TypeScript 2.0, you can provide an explicit this parameter. this parameters are fake parameters that come first in the parameter list of a function

    Notice that this won't get translated into js, so it's not a real argument in the function.

    0 讨论(0)
提交回复
热议问题