UNPKG

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