UNPKG

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