What is the equivalent of promise<void> in observables?

Viewed 605

I am using angular, so typescript, and try to return a promise from an observable.

What is the right way to do this?

I tried:

of(EMPTY).toPromise() // error: Promise<Observable<never>>' is not assignable to type Promise<void>

of(null).toPromise() // no error but not sure if it is the right way

of().toPromise // error: Promise<Observable<unknown>>' is not assignable to type Promise<void> 

Update:

// this is the interface that declares it

export interface CustomStoreOptions extends StoreOptions<CustomStore> {   
   /** Specifies a custom implementation of the remove(key) method. */
    remove?: ((key: any | string | number) => Promise<void> | JQueryPromise<void>);   
}

so it is called:

let store = new CustomStore({     
        remove: key => {
          // return ...
        }
      });
1 Answers

You can write it as follows to get the equivalent of Promise<void>

 of(void(0))

You can also create a Subject that emits no data

 const s = new Subject<void>();
 s.next(void(0));
Related