Disallow using shareReplay({ refCount: false }) before takeUntil (rxjs-x/no-sharereplay-before-takeuntil)

November 25, 2025 ยท View on GitHub

๐Ÿ’ผ This rule is enabled in the ๐Ÿ”’ strict config.

This rule effects failures if the shareReplay operator is used without its reference counting behavior and placed in an observable composition before takeUntil.

Rule details

Examples of incorrect code for this rule:

source.pipe(
    shareReplay(),
    takeUntil(notifier),
);

Examples of correct code for this rule:

source.pipe(
    shareReplay({ refCount: true }),
    takeUntil(notifier),
);

Options

NameDescriptionTypeDefault
takeUntilAliasList of operators to treat as takeUntil.Array[takeUntilDestroyed]

This rule accepts a single option which allows specifying any potential aliases for takeUntil. The purpose of this is to enforce the "no shareReplay before" rule on other operators that are used as takeUntil(). The default configuration is Angular friendly by specifying takeUntilDestroyed as an alias.

When Not To Use It

If you are confident your project uses shareReplay and takeUntil correctly, then you may not need this rule.

Further reading

Resources