import { DestroyRef } from '@angular/core'; import type { Observable, Subscription } from 'rxjs'; export type Observer = { next?: (value: T) => void; error?: (err: unknown) => void; complete?: () => void; }; /** Subscribe to an Observable with automatic teardown when the host * component is destroyed. Equivalent to * `observable.pipe(takeUntilDestroyed(destroyRef)).subscribe(observer)`, * collapsed into one call so consumers can't forget the cleanup * operator (the most common Angular memory-leak source). * * `inject(DestroyRef)` is only legal in an Angular injection context * (constructor, field initializer, factory, * `runInInjectionContext`). Calling `useSubscription` without a * captured `DestroyRef` from `ngOnInit` or any other lifecycle hook * will throw `NG0203`. For those call sites, capture the ref once in * a field initializer (`private destroyRef = inject(DestroyRef);`) * and pass it as the third argument: * * ```ts * ngOnInit() { * useSubscription(this.events$, (event) => { ... }, this.destroyRef); * } * ``` * * Note: this composable handles teardown only — it does not trigger * change detection on emissions. If the observer mutates state that * drives the template, store that state in a `signal()` so updates * propagate in zoneless Angular. */ export declare function useSubscription(observable: Observable, next: (value: T) => void, destroyRef?: DestroyRef): Subscription; export declare function useSubscription(observable: Observable, observer: Observer, destroyRef?: DestroyRef): Subscription;