808d924f27eb9d06dbd6dd07dfcdb78dee23de6c5fdb030ab921641b3a035ddb37ad35c0fff6d04bb7f9636601dd5642f9bf60c563cc8e4c816e685ab8d448 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /// <reference lib="esnext.asynciterable" />
  2. import { Observable } from './Observable';
  3. import { Subscription } from './Subscription';
  4. /**
  5. * Note: This will add Symbol.observable globally for all TypeScript users,
  6. * however, we are no longer polyfilling Symbol.observable
  7. */
  8. declare global {
  9. interface SymbolConstructor {
  10. readonly observable: symbol;
  11. }
  12. }
  13. /**
  14. * A function type interface that describes a function that accepts one parameter `T`
  15. * and returns another parameter `R`.
  16. *
  17. * Usually used to describe {@link OperatorFunction} - it always takes a single
  18. * parameter (the source Observable) and returns another Observable.
  19. */
  20. export interface UnaryFunction<T, R> {
  21. (source: T): R;
  22. }
  23. export interface OperatorFunction<T, R> extends UnaryFunction<Observable<T>, Observable<R>> {
  24. }
  25. export declare type FactoryOrValue<T> = T | (() => T);
  26. /**
  27. * A function type interface that describes a function that accepts and returns a parameter of the same type.
  28. *
  29. * Used to describe {@link OperatorFunction} with the only one type: `OperatorFunction<T, T>`.
  30. *
  31. */
  32. export interface MonoTypeOperatorFunction<T> extends OperatorFunction<T, T> {
  33. }
  34. /**
  35. * A value and the time at which it was emitted.
  36. *
  37. * Emitted by the `timestamp` operator
  38. *
  39. * @see {@link timestamp}
  40. */
  41. export interface Timestamp<T> {
  42. value: T;
  43. /**
  44. * The timestamp. By default, this is in epoch milliseconds.
  45. * Could vary based on the timestamp provider passed to the operator.
  46. */
  47. timestamp: number;
  48. }
  49. /**
  50. * A value emitted and the amount of time since the last value was emitted.
  51. *
  52. * Emitted by the `timeInterval` operator.
  53. *
  54. * @see {@link timeInterval}
  55. */
  56. export interface TimeInterval<T> {
  57. value: T;
  58. /**
  59. * The amount of time between this value's emission and the previous value's emission.
  60. * If this is the first emitted value, then it will be the amount of time since subscription
  61. * started.
  62. */
  63. interval: number;
  64. }
  65. export interface Unsubscribable {
  66. unsubscribe(): void;
  67. }
  68. export declare type TeardownLogic = Subscription | Unsubscribable | (() => void) | void;
  69. export interface SubscriptionLike extends Unsubscribable {
  70. unsubscribe(): void;
  71. readonly closed: boolean;
  72. }
  73. /**
  74. * @deprecated Do not use. Most likely you want to use `ObservableInput`. Will be removed in v8.
  75. */
  76. export declare type SubscribableOrPromise<T> = Subscribable<T> | Subscribable<never> | PromiseLike<T> | InteropObservable<T>;
  77. /** OBSERVABLE INTERFACES */
  78. export interface Subscribable<T> {
  79. subscribe(observer: Partial<Observer<T>>): Unsubscribable;
  80. }
  81. /**
  82. * Valid types that can be converted to observables.
  83. */
  84. export declare type ObservableInput<T> = Observable<T> | InteropObservable<T> | AsyncIterable<T> | PromiseLike<T> | ArrayLike<T> | Iterable<T> | ReadableStreamLike<T>;
  85. /**
  86. * @deprecated Renamed to {@link InteropObservable }. Will be removed in v8.
  87. */
  88. export declare type ObservableLike<T> = InteropObservable<T>;
  89. /**
  90. * An object that implements the `Symbol.observable` interface.
  91. */
  92. export interface InteropObservable<T> {
  93. [Symbol.observable]: () => Subscribable<T>;
  94. }
  95. /**
  96. * A notification representing a "next" from an observable.
  97. * Can be used with {@link dematerialize}.
  98. */
  99. export interface NextNotification<T> {
  100. /** The kind of notification. Always "N" */
  101. kind: 'N';
  102. /** The value of the notification. */
  103. value: T;
  104. }
  105. /**
  106. * A notification representing an "error" from an observable.
  107. * Can be used with {@link dematerialize}.
  108. */
  109. export interface ErrorNotification {
  110. /** The kind of notification. Always "E" */
  111. kind: 'E';
  112. error: any;
  113. }
  114. /**
  115. * A notification representing a "completion" from an observable.
  116. * Can be used with {@link dematerialize}.
  117. */
  118. export interface CompleteNotification {
  119. kind: 'C';
  120. }
  121. /**
  122. * Valid observable notification types.
  123. */
  124. export declare type ObservableNotification<T> = NextNotification<T> | ErrorNotification | CompleteNotification;
  125. export interface NextObserver<T> {
  126. closed?: boolean;
  127. next: (value: T) => void;
  128. error?: (err: any) => void;
  129. complete?: () => void;
  130. }
  131. export interface ErrorObserver<T> {
  132. closed?: boolean;
  133. next?: (value: T) => void;
  134. error: (err: any) => void;
  135. complete?: () => void;
  136. }
  137. export interface CompletionObserver<T> {
  138. closed?: boolean;
  139. next?: (value: T) => void;
  140. error?: (err: any) => void;
  141. complete: () => void;
  142. }
  143. export declare type PartialObserver<T> = NextObserver<T> | ErrorObserver<T> | CompletionObserver<T>;
  144. /**
  145. * An object interface that defines a set of callback functions a user can use to get
  146. * notified of any set of {@link Observable}
  147. * {@link guide/glossary-and-semantics#notification notification} events.
  148. *
  149. * For more info, please refer to {@link guide/observer this guide}.
  150. */
  151. export interface Observer<T> {
  152. /**
  153. * A callback function that gets called by the producer during the subscription when
  154. * the producer "has" the `value`. It won't be called if `error` or `complete` callback
  155. * functions have been called, nor after the consumer has unsubscribed.
  156. *
  157. * For more info, please refer to {@link guide/glossary-and-semantics#next this guide}.
  158. */
  159. next: (value: T) => void;
  160. /**
  161. * A callback function that gets called by the producer if and when it encountered a
  162. * problem of any kind. The errored value will be provided through the `err` parameter.
  163. * This callback can't be called more than one time, it can't be called if the
  164. * `complete` callback function have been called previously, nor it can't be called if
  165. * the consumer has unsubscribed.
  166. *
  167. * For more info, please refer to {@link guide/glossary-and-semantics#error this guide}.
  168. */
  169. error: (err: any) => void;
  170. /**
  171. * A callback function that gets called by the producer if and when it has no more
  172. * values to provide (by calling `next` callback function). This means that no error
  173. * has happened. This callback can't be called more than one time, it can't be called
  174. * if the `error` callback function have been called previously, nor it can't be called
  175. * if the consumer has unsubscribed.
  176. *
  177. * For more info, please refer to {@link guide/glossary-and-semantics#complete this guide}.
  178. */
  179. complete: () => void;
  180. }
  181. export interface SubjectLike<T> extends Observer<T>, Subscribable<T> {
  182. }
  183. export interface SchedulerLike extends TimestampProvider {
  184. schedule<T>(work: (this: SchedulerAction<T>, state: T) => void, delay: number, state: T): Subscription;
  185. schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay: number, state?: T): Subscription;
  186. schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay?: number, state?: T): Subscription;
  187. }
  188. export interface SchedulerAction<T> extends Subscription {
  189. schedule(state?: T, delay?: number): Subscription;
  190. }
  191. /**
  192. * This is a type that provides a method to allow RxJS to create a numeric timestamp
  193. */
  194. export interface TimestampProvider {
  195. /**
  196. * Returns a timestamp as a number.
  197. *
  198. * This is used by types like `ReplaySubject` or operators like `timestamp` to calculate
  199. * the amount of time passed between events.
  200. */
  201. now(): number;
  202. }
  203. /**
  204. * Extracts the type from an `ObservableInput<any>`. If you have
  205. * `O extends ObservableInput<any>` and you pass in `Observable<number>`, or
  206. * `Promise<number>`, etc, it will type as `number`.
  207. */
  208. export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;
  209. /**
  210. * Extracts a union of element types from an `ObservableInput<any>[]`.
  211. * If you have `O extends ObservableInput<any>[]` and you pass in
  212. * `Observable<string>[]` or `Promise<string>[]` you would get
  213. * back a type of `string`.
  214. * If you pass in `[Observable<string>, Observable<number>]` you would
  215. * get back a type of `string | number`.
  216. */
  217. export declare type ObservedValueUnionFromArray<X> = X extends Array<ObservableInput<infer T>> ? T : never;
  218. /**
  219. * @deprecated Renamed to {@link ObservedValueUnionFromArray}. Will be removed in v8.
  220. */
  221. export declare type ObservedValuesFromArray<X> = ObservedValueUnionFromArray<X>;
  222. /**
  223. * Extracts a tuple of element types from an `ObservableInput<any>[]`.
  224. * If you have `O extends ObservableInput<any>[]` and you pass in
  225. * `[Observable<string>, Observable<number>]` you would get back a type
  226. * of `[string, number]`.
  227. */
  228. export declare type ObservedValueTupleFromArray<X> = {
  229. [K in keyof X]: ObservedValueOf<X[K]>;
  230. };
  231. /**
  232. * Used to infer types from arguments to functions like {@link forkJoin}.
  233. * So that you can have `forkJoin([Observable<A>, PromiseLike<B>]): Observable<[A, B]>`
  234. * et al.
  235. */
  236. export declare type ObservableInputTuple<T> = {
  237. [K in keyof T]: ObservableInput<T[K]>;
  238. };
  239. /**
  240. * Constructs a new tuple with the specified type at the head.
  241. * If you declare `Cons<A, [B, C]>` you will get back `[A, B, C]`.
  242. */
  243. export declare type Cons<X, Y extends readonly any[]> = ((arg: X, ...rest: Y) => any) extends (...args: infer U) => any ? U : never;
  244. /**
  245. * Extracts the head of a tuple.
  246. * If you declare `Head<[A, B, C]>` you will get back `A`.
  247. */
  248. export declare type Head<X extends readonly any[]> = ((...args: X) => any) extends (arg: infer U, ...rest: any[]) => any ? U : never;
  249. /**
  250. * Extracts the tail of a tuple.
  251. * If you declare `Tail<[A, B, C]>` you will get back `[B, C]`.
  252. */
  253. export declare type Tail<X extends readonly any[]> = ((...args: X) => any) extends (arg: any, ...rest: infer U) => any ? U : never;
  254. /**
  255. * Extracts the generic value from an Array type.
  256. * If you have `T extends Array<any>`, and pass a `string[]` to it,
  257. * `ValueFromArray<T>` will return the actual type of `string`.
  258. */
  259. export declare type ValueFromArray<A extends readonly unknown[]> = A extends Array<infer T> ? T : never;
  260. /**
  261. * Gets the value type from an {@link ObservableNotification}, if possible.
  262. */
  263. export declare type ValueFromNotification<T> = T extends {
  264. kind: 'N' | 'E' | 'C';
  265. } ? T extends NextNotification<any> ? T extends {
  266. value: infer V;
  267. } ? V : undefined : never : never;
  268. /**
  269. * A simple type to represent a gamut of "falsy" values... with a notable exception:
  270. * `NaN` is "falsy" however, it is not and cannot be typed via TypeScript. See
  271. * comments here: https://github.com/microsoft/TypeScript/issues/28682#issuecomment-707142417
  272. */
  273. export declare type Falsy = null | undefined | false | 0 | -0 | 0n | '';
  274. export declare type TruthyTypesOf<T> = T extends Falsy ? never : T;
  275. interface ReadableStreamDefaultReaderLike<T> {
  276. read(): PromiseLike<{
  277. done: false;
  278. value: T;
  279. } | {
  280. done: true;
  281. value?: undefined;
  282. }>;
  283. releaseLock(): void;
  284. }
  285. /**
  286. * The base signature RxJS will look for to identify and use
  287. * a [ReadableStream](https://streams.spec.whatwg.org/#rs-class)
  288. * as an {@link ObservableInput} source.
  289. */
  290. export interface ReadableStreamLike<T> {
  291. getReader(): ReadableStreamDefaultReaderLike<T>;
  292. }
  293. /**
  294. * An observable with a `connect` method that is used to create a subscription
  295. * to an underlying source, connecting it with all consumers via a multicast.
  296. */
  297. export interface Connectable<T> extends Observable<T> {
  298. /**
  299. * (Idempotent) Calling this method will connect the underlying source observable to all subscribed consumers
  300. * through an underlying {@link Subject}.
  301. * @returns A subscription, that when unsubscribed, will "disconnect" the source from the connector subject,
  302. * severing notifications to all consumers.
  303. */
  304. connect(): Subscription;
  305. }
  306. export {};
  307. //# sourceMappingURL=types.d.ts.map