Use Observable <void> or Observable <any> to emit a null value?

There are cases where the return value of the async operation is not relevant or not given at all. In these cases, the signatures of asynchronous operation methods are often defined Observable<any>either Promise<any>as the return value.

Example

For example, Ionic2 NavController defines:

/** // ...
 * @returns {Promise} Returns a promise which is resolved when the transition has completed.
 */
 abstract remove(/* ... */): Promise<any>;

Despite the actual implementation, I can’t say whether the value is really not selected (for example, nullor undefined), or I could extract some useful information from the emitted values.

Question Observable<void>:?

I have not seen Observable<void>or Promise<void>in the wild. Using this, it would be clear that there is no emitted useful value. Are there technical reasons not to use a type voidwith observables? Or why no one uses this to denote empty values?

+4
source share
1 answer

Are there any technical reasons not to use the void type with observables? Or why no one uses this to indicate empty values

There is no danger to use Promise<void>, as far as I know.

+3
source

Source: https://habr.com/ru/post/1655089/


All Articles