During my service refactoring process, I encountered a frustrating issue. The API I am working with returns an object with various optional properties. To work with these properties, I need to check if they are undefined or not using an if statement, otherwise, errors occur. I attempted to simplify this process by incorporating the check into the filter operator after refactoring. However, despite my efforts, I still receive linting errors.
interface OptionalObject {
values?: number[]
}
const obs$$ = new BehaviorSubject<OptionalObject>({});
obs$$.pipe(
filter((val) => !!val.values),
map((val) => val.values.length) // Object is possibly 'undefined'
).subscribe(() => {
});
I believe ESLint is being utilized in my project.
Even though checking with an if statement works, I prefer to use Rxjs's filter method for my implementation.