Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

There are cases where the return value of an async operation is not important or not given at all. In those cases, method signatures of async operations often define Observable<any> or Promise<any> as return value.

Example

For example the Ionic2 NavController defines:

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

Without looking at the actual implementation I cannot tell whether there really is no value emitted (e.g. null or undefined) or whether I could extract some useful information from the emitted values.

Question: Observable<void>?

I haven't seen Observable<void> or Promise<void> in the wild. By using that it would be clear that there is no useful value being emitted. Are there any technical reasons not to use the void type with observables? Or why is no one using that to designate empty values?

like image 667
Fabian Keller Avatar asked Oct 18 '22 01:10

Fabian Keller


1 Answers

Are there any technical reasons not to use the void type with observables? Or why is no one using that to designate empty values

There is no hazard in using Promise<void> as far as I am aware.

like image 108
basarat Avatar answered Oct 27 '22 09:10

basarat