Disallow using firstValueFrom, lastValueFrom, first, and last without specifying a default value (rxjs-x/no-ignored-default-value)
April 18, 2025 ยท View on GitHub
๐ผ This rule is enabled in the ๐ strict config.
๐ญ This rule requires type information.
This rule prevents EmptyError rejections if there were no emissions from firstValueFrom, lastValueFrom, first, or last by requiring defaultValue.
Rule details
Examples of incorrect code for this rule:
import { Subject, firstValueFrom } from "rxjs";
const sub = new Subject();
const result = firstValueFrom(sub);
sub.complete();
Examples of correct code for this rule:
import { Subject, firstValueFrom } from "rxjs";
const sub = new Subject();
const result = firstValueFrom(sub, { defaultValue: null });
sub.complete();
When Not To Use It
If you intentionally want EmptyError rejections when the observable completes, then you may not need this rule.
You might consider using ESLint disable comments for specific situations instead of completely disabling this rule.
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.