Is there any way to get a hint when I forgot to add a subscribe()
call on an observable?
// somewhere in some class
function deleteIt(): Observable<any> {
return httpService.delete('/foo');
}
// some other place
deleteIt(); // 🐛 this statement has no effect and should warn
deleteIt().subscribe(); // this is fine
No, there isn't a rule right now. You might want to propose one in https://github.com/cartant/eslint-plugin-rxjs and/or https://github.com/cartant/eslint-plugin-rxjs-angular.
Otherwise, you could write your own custom lint rule: https://eslint.org/docs/latest/extend/custom-rules. Presumably you'd want the rule to only apply to values that are the Observable
type, so you'll need to use something like typescript-eslint's Typed Rules guide to use TypeScript type information.