I wanted to understand the intellisense displayed in the visual code which got me more confused
debounce(
durationSelector: (value: {}) => SubscribableOrPromise<any>
): MonoTypeOperatorFunction<{}>
from the above example, I think I understood the following:
debounce
is the name of the functiondurationSelector
is a function which that a single parameter:
a. value
which takes Object as parameter
b. SubscribableOrPromise<any>
is the type that the function is going to return
MonoTypeOperatorFunction<{}>
, not able to understand how a function can return MonoTypeOperatorFunction<{}>
when it already returns SubscribableOrPromise<any>
, this is where I am confused and not able to understandnot able to understand how a function can return
MonoTypeOperatorFunction<{}>
when it already returnsSubscribableOrPromise<any>
That's not what is being described here, you don't have one function that returns MonoTypeOperatorFunction
and also SubscribableOrPromise
. You have two functions:
debounce
; anddurationSelector
argument to debounce
(which may be anonymous in your code).debounce
returns MonoTypeOperatorFunction<{}>
, so the result can be passed to pipe
(which takes OperatorFunction
s, of which that's a subtype).
debounce
requires the function as you're passing as an argument to it to return SubscribableOrPromise<any>
, the line:
(value: {}) => SubscribableOrPromise<any>
is the declaration of the argument, durationSelector
; it's a function type.
I'd recommend reading up on "higher-order functions", as that's a really important concept to understand if you're going to use RxJS.