found this piece of code which is actually working but eslint is complaining about the misused promise
this.subject$.pipe(delay(this.debounceTime || 0)).subscribe(async ({ entry, observer }) => {
const target = entry.target as HTMLElement;
const isStillVisible = await this.isVisible(target);
isStillVisible ? this.visible.emit() : this.invisible.emit();
});
ESLint: Promise returned in function argument where a void return was expected.(@typescript-eslint/no-misused-promises)
i need to refactor this function to get rid of the eslint error
tried asynchronous IIFE inside the callback
2
Answers
An
async
function implicitly returns a promise. You can change your callback to the following and it should still behave the same way but get rid of the error you are getting.This way the callback you pass to subscribe no longer returns a promise.
You can convert promises via
from
but as @Eddi commented (thanks!) this isn’t required forswitchMap
since this converts to an observable under the hoodI don’t think the order of the switchMap and delay matters but I’d check this.