index.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * @license Angular v20.1.0
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { OutputRef, DestroyRef, Injector, Signal } from '../chrome_dev_tools_performance.d.js';
  7. import { OutputOptions, BaseResourceOptions, ResourceLoaderParams, ResourceRef } from '../api.d.js';
  8. import '../event_dispatcher.d.js';
  9. import { Observable, MonoTypeOperatorFunction, Subscribable } from 'rxjs';
  10. import { ValueEqualityFn } from '../graph.d.js';
  11. /**
  12. * Declares an Angular output that is using an RxJS observable as a source
  13. * for events dispatched to parent subscribers.
  14. *
  15. * The behavior for an observable as source is defined as followed:
  16. * 1. New values are forwarded to the Angular output (next notifications).
  17. * 2. Errors notifications are not handled by Angular. You need to handle these manually.
  18. * For example by using `catchError`.
  19. * 3. Completion notifications stop the output from emitting new values.
  20. *
  21. * @usageNotes
  22. * Initialize an output in your directive by declaring a
  23. * class field and initializing it with the `outputFromObservable()` function.
  24. *
  25. * ```ts
  26. * @Directive({..})
  27. * export class MyDir {
  28. * nameChange$ = <some-observable>;
  29. * nameChange = outputFromObservable(this.nameChange$);
  30. * }
  31. * ```
  32. *
  33. * @publicApi 19.0
  34. */
  35. declare function outputFromObservable<T>(observable: Observable<T>, opts?: OutputOptions): OutputRef<T>;
  36. /**
  37. * Converts an Angular output declared via `output()` or `outputFromObservable()`
  38. * to an observable.
  39. *
  40. * You can subscribe to the output via `Observable.subscribe` then.
  41. *
  42. * @publicApi 19.0
  43. */
  44. declare function outputToObservable<T>(ref: OutputRef<T>): Observable<T>;
  45. /**
  46. * Operator which completes the Observable when the calling context (component, directive, service,
  47. * etc) is destroyed.
  48. *
  49. * @param destroyRef optionally, the `DestroyRef` representing the current context. This can be
  50. * passed explicitly to use `takeUntilDestroyed` outside of an [injection
  51. * context](guide/di/dependency-injection-context). Otherwise, the current `DestroyRef` is injected.
  52. *
  53. * @publicApi 19.0
  54. */
  55. declare function takeUntilDestroyed<T>(destroyRef?: DestroyRef): MonoTypeOperatorFunction<T>;
  56. /**
  57. * Options for `toObservable`.
  58. *
  59. * @publicApi 20.0
  60. */
  61. interface ToObservableOptions {
  62. /**
  63. * The `Injector` to use when creating the underlying `effect` which watches the signal.
  64. *
  65. * If this isn't specified, the current [injection context](guide/di/dependency-injection-context)
  66. * will be used.
  67. */
  68. injector?: Injector;
  69. }
  70. /**
  71. * Exposes the value of an Angular `Signal` as an RxJS `Observable`.
  72. *
  73. * The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
  74. *
  75. * `toObservable` must be called in an injection context unless an injector is provided via options.
  76. *
  77. * @publicApi 20.0
  78. */
  79. declare function toObservable<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T>;
  80. /**
  81. * Options for `toSignal`.
  82. *
  83. * @publicApi 20.0
  84. */
  85. interface ToSignalOptions<T> {
  86. /**
  87. * Initial value for the signal produced by `toSignal`.
  88. *
  89. * This will be the value of the signal until the observable emits its first value.
  90. */
  91. initialValue?: unknown;
  92. /**
  93. * Whether to require that the observable emits synchronously when `toSignal` subscribes.
  94. *
  95. * If this is `true`, `toSignal` will assert that the observable produces a value immediately upon
  96. * subscription. Setting this option removes the need to either deal with `undefined` in the
  97. * signal type or provide an `initialValue`, at the cost of a runtime error if this requirement is
  98. * not met.
  99. */
  100. requireSync?: boolean;
  101. /**
  102. * `Injector` which will provide the `DestroyRef` used to clean up the Observable subscription.
  103. *
  104. * If this is not provided, a `DestroyRef` will be retrieved from the current [injection
  105. * context](guide/di/dependency-injection-context), unless manual cleanup is requested.
  106. */
  107. injector?: Injector;
  108. /**
  109. * Whether the subscription should be automatically cleaned up (via `DestroyRef`) when
  110. * `toSignal`'s creation context is destroyed.
  111. *
  112. * If manual cleanup is enabled, then `DestroyRef` is not used, and the subscription will persist
  113. * until the `Observable` itself completes.
  114. */
  115. manualCleanup?: boolean;
  116. /**
  117. * A comparison function which defines equality for values emitted by the observable.
  118. *
  119. * Equality comparisons are executed against the initial value if one is provided.
  120. */
  121. equal?: ValueEqualityFn<T>;
  122. }
  123. declare function toSignal<T>(source: Observable<T> | Subscribable<T>): Signal<T | undefined>;
  124. declare function toSignal<T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | undefined>> & {
  125. initialValue?: undefined;
  126. requireSync?: false;
  127. }): Signal<T | undefined>;
  128. declare function toSignal<T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | null>> & {
  129. initialValue?: null;
  130. requireSync?: false;
  131. }): Signal<T | null>;
  132. declare function toSignal<T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T>> & {
  133. initialValue?: undefined;
  134. requireSync: true;
  135. }): Signal<T>;
  136. declare function toSignal<T, const U extends T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | U>> & {
  137. initialValue: U;
  138. requireSync?: false;
  139. }): Signal<T | U>;
  140. /**
  141. * Operator which makes the application unstable until the observable emits, completes, errors, or is unsubscribed.
  142. *
  143. * Use this operator in observables whose subscriptions are important for rendering and should be included in SSR serialization.
  144. *
  145. * @param injector The `Injector` to use during creation. If this is not provided, the current injection context will be used instead (via `inject`).
  146. *
  147. * @developerPreview 20.0
  148. */
  149. declare function pendingUntilEvent<T>(injector?: Injector): MonoTypeOperatorFunction<T>;
  150. /**
  151. * Like `ResourceOptions` but uses an RxJS-based `loader`.
  152. *
  153. * @experimental
  154. */
  155. interface RxResourceOptions<T, R> extends BaseResourceOptions<T, R> {
  156. stream: (params: ResourceLoaderParams<R>) => Observable<T>;
  157. }
  158. /**
  159. * Like `resource` but uses an RxJS based `loader` which maps the request to an `Observable` of the
  160. * resource's value.
  161. *
  162. * @experimental
  163. */
  164. declare function rxResource<T, R>(opts: RxResourceOptions<T, R> & {
  165. defaultValue: NoInfer<T>;
  166. }): ResourceRef<T>;
  167. /**
  168. * Like `resource` but uses an RxJS based `loader` which maps the request to an `Observable` of the
  169. * resource's value.
  170. *
  171. * @experimental
  172. */
  173. declare function rxResource<T, R>(opts: RxResourceOptions<T, R>): ResourceRef<T | undefined>;
  174. export { outputFromObservable, outputToObservable, pendingUntilEvent, rxResource, takeUntilDestroyed, toObservable, toSignal };
  175. export type { RxResourceOptions, ToObservableOptions, ToSignalOptions };