UNPKG

56.7 kBTypeScriptView Raw
1/// <reference types="rx-core" />
2/// <reference types="rx-core-binding" />
3
4declare namespace Rx {
5 namespace internals {
6 function isEqual(left: any, right: any): boolean;
7 function addRef<T>(xs: Observable<T>, r: { getDisposable(): IDisposable }): Observable<T>;
8
9 // Priority Queue for Scheduling
10 class PriorityQueue<TTime> {
11 constructor(capacity: number);
12
13 length: number;
14
15 isHigherPriority(left: number, right: number): boolean;
16 percolate(index: number): void;
17 heapify(index: number): void;
18 peek(): ScheduledItem<TTime>;
19 removeAt(index: number): void;
20 dequeue(): ScheduledItem<TTime>;
21 enqueue(item: ScheduledItem<TTime>): void;
22 remove(item: ScheduledItem<TTime>): boolean;
23
24 static count: number;
25 }
26
27 class ScheduledItem<TTime> {
28 constructor(
29 scheduler: IScheduler,
30 state: any,
31 action: (scheduler: IScheduler, state: any) => IDisposable,
32 dueTime: TTime,
33 comparer?: (x: TTime, y: TTime) => number,
34 );
35
36 scheduler: IScheduler;
37 state: TTime;
38 action: (scheduler: IScheduler, state: any) => IDisposable;
39 dueTime: TTime;
40 comparer: (x: TTime, y: TTime) => number;
41 disposable: SingleAssignmentDisposable;
42
43 invoke(): void;
44 compareTo(other: ScheduledItem<TTime>): number;
45 isCancelled(): boolean;
46 invokeCore(): IDisposable;
47 }
48 }
49
50 namespace config {
51 let Promise: {
52 new<T>(
53 resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void,
54 ): IPromise<T>;
55 };
56 }
57
58 namespace helpers {
59 function noop(): void;
60 function notDefined(value: any): boolean;
61 function identity<T>(value: T): T;
62 function defaultNow(): number;
63 function defaultComparer(left: any, right: any): boolean;
64 function defaultSubComparer(left: any, right: any): number;
65 function defaultKeySerializer(key: any): string;
66 function defaultError(err: any): void;
67 function isPromise(p: any): boolean;
68 function asArray<T>(...args: T[]): T[];
69 function not(value: any): boolean;
70 function isFunction(value: any): boolean;
71 }
72
73 class CompositeDisposable implements IDisposable {
74 constructor(...disposables: IDisposable[]);
75 constructor(disposables: IDisposable[]);
76
77 isDisposed: boolean;
78 length: number;
79
80 dispose(): void;
81 add(item: IDisposable): void;
82 remove(item: IDisposable): boolean;
83 toArray(): IDisposable[];
84 }
85
86 class Disposable implements IDisposable {
87 constructor(action: () => void);
88
89 static create(action: () => void): IDisposable;
90 static empty: IDisposable;
91
92 dispose(): void;
93 }
94
95 // Single assignment
96 class SingleAssignmentDisposable implements IDisposable {
97 constructor();
98
99 isDisposed: boolean;
100 current: IDisposable;
101
102 dispose(): void;
103 getDisposable(): IDisposable;
104 setDisposable(value: IDisposable): void;
105 }
106
107 // SerialDisposable it's an alias of SingleAssignmentDisposable
108 class SerialDisposable extends SingleAssignmentDisposable {
109 constructor();
110 }
111
112 class RefCountDisposable implements IDisposable {
113 constructor(disposable: IDisposable);
114
115 dispose(): void;
116
117 isDisposed: boolean;
118 getDisposable(): IDisposable;
119 }
120
121 interface IScheduler {
122 now(): number;
123 isScheduler(value: any): boolean;
124
125 schedule(action: () => void): IDisposable;
126 scheduleWithState<TState>(
127 state: TState,
128 action: (scheduler: IScheduler, state: TState) => IDisposable,
129 ): IDisposable;
130 scheduleWithAbsolute(dueTime: number, action: () => void): IDisposable;
131 scheduleWithAbsoluteAndState<TState>(
132 state: TState,
133 dueTime: number,
134 action: (scheduler: IScheduler, state: TState) => IDisposable,
135 ): IDisposable;
136 scheduleWithRelative(dueTime: number, action: () => void): IDisposable;
137 scheduleWithRelativeAndState<TState>(
138 state: TState,
139 dueTime: number,
140 action: (scheduler: IScheduler, state: TState) => IDisposable,
141 ): IDisposable;
142
143 scheduleRecursive(action: (action: () => void) => void): IDisposable;
144 scheduleRecursiveWithState<TState>(
145 state: TState,
146 action: (state: TState, action: (state: TState) => void) => void,
147 ): IDisposable;
148 scheduleRecursiveWithAbsolute(
149 dueTime: number,
150 action: (action: (dueTime: number) => void) => void,
151 ): IDisposable;
152 scheduleRecursiveWithAbsoluteAndState<TState>(
153 state: TState,
154 dueTime: number,
155 action: (state: TState, action: (state: TState, dueTime: number) => void) => void,
156 ): IDisposable;
157 scheduleRecursiveWithRelative(
158 dueTime: number,
159 action: (action: (dueTime: number) => void) => void,
160 ): IDisposable;
161 scheduleRecursiveWithRelativeAndState<TState>(
162 state: TState,
163 dueTime: number,
164 action: (state: TState, action: (state: TState, dueTime: number) => void) => void,
165 ): IDisposable;
166
167 schedulePeriodic(period: number, action: () => void): IDisposable;
168 schedulePeriodicWithState<TState>(
169 state: TState,
170 period: number,
171 action: (state: TState) => TState,
172 ): IDisposable;
173 }
174
175 interface Scheduler extends IScheduler {
176 }
177
178 interface SchedulerStatic {
179 new(
180 now: () => number,
181 schedule: (state: any, action: (scheduler: IScheduler, state: any) => IDisposable) => IDisposable,
182 scheduleRelative: (
183 state: any,
184 dueTime: number,
185 action: (scheduler: IScheduler, state: any) => IDisposable,
186 ) => IDisposable,
187 scheduleAbsolute: (
188 state: any,
189 dueTime: number,
190 action: (scheduler: IScheduler, state: any) => IDisposable,
191 ) => IDisposable,
192 ): Scheduler;
193
194 normalize(timeSpan: number): number;
195
196 immediate: IScheduler;
197 currentThread: ICurrentThreadScheduler;
198 default: IScheduler; // alias for Scheduler.timeout
199 timeout: IScheduler;
200 }
201
202 const Scheduler: SchedulerStatic;
203
204 // Current Thread IScheduler
205 interface ICurrentThreadScheduler extends IScheduler {
206 scheduleRequired(): boolean;
207 }
208
209 // Notifications
210 class Notification<T> {
211 accept(observer: IObserver<T>): void;
212 accept<TResult>(
213 onNext: (value: T) => TResult,
214 onError?: (exception: any) => TResult,
215 onCompleted?: () => TResult,
216 ): TResult;
217 toObservable(scheduler?: IScheduler): Observable<T>;
218 hasValue: boolean;
219 equals(other: Notification<T>): boolean;
220 kind: string;
221 value: T;
222 exception: any;
223
224 static createOnNext<T>(value: T): Notification<T>;
225 static createOnError<T>(exception: any): Notification<T>;
226 static createOnCompleted<T>(): Notification<T>;
227 }
228
229 // Observer
230 interface IObserver<T> {
231 onNext(value: T): void;
232 onError(exception: any): void;
233 onCompleted(): void;
234 }
235
236 interface Observer<T> extends IObserver<T> {
237 toNotifier(): (notification: Notification<T>) => void;
238 asObserver(): Observer<T>;
239 }
240
241 interface ObserverStatic {
242 create<T>(
243 onNext?: (value: T) => void,
244 onError?: (exception: any) => void,
245 onCompleted?: () => void,
246 ): Observer<T>;
247 fromNotifier<T>(handler: (notification: Notification<T>, thisArg?: any) => void): Observer<T>;
248 }
249
250 const Observer: ObserverStatic;
251
252 interface IObservable<T> {
253 subscribe(observer: Observer<T>): IDisposable;
254 subscribe(
255 onNext?: (value: T) => void,
256 onError?: (exception: any) => void,
257 onCompleted?: () => void,
258 ): IDisposable;
259
260 subscribeOnNext(onNext: (value: T) => void, thisArg?: any): IDisposable;
261 subscribeOnError(onError: (exception: any) => void, thisArg?: any): IDisposable;
262 subscribeOnCompleted(onCompleted: () => void, thisArg?: any): IDisposable;
263 }
264
265 interface Observable<T> extends IObservable<T> {
266 forEach(onNext?: (value: T) => void, onError?: (exception: any) => void, onCompleted?: () => void): IDisposable; // alias for subscribe
267 toArray(): Observable<T[]>;
268
269 catch(handler: (exception: Error) => IPromise<T> | Observable<T>): Observable<T>;
270 catch(second: Observable<T>): Observable<T>;
271 catchException(handler: (exception: Error) => IPromise<T> | Observable<T>): Observable<T>; // alias for catch
272 catchException(second: Observable<T>): Observable<T>; // alias for catch
273 combineLatest<T2>(second: Observable<T2> | IPromise<T2>): Observable<[T, T2]>;
274 combineLatest<T2, TResult>(
275 second: Observable<T2> | IPromise<T2>,
276 resultSelector: (v1: T, v2: T2) => TResult,
277 ): Observable<TResult>;
278 combineLatest<T2, T3>(
279 second: Observable<T2> | IPromise<T2>,
280 third: Observable<T3> | IPromise<T3>,
281 ): Observable<[T, T2, T3]>;
282 combineLatest<T2, T3, TResult>(
283 second: Observable<T2> | IPromise<T2>,
284 third: Observable<T3> | IPromise<T3>,
285 resultSelector: (v1: T, v2: T2, v3: T3) => TResult,
286 ): Observable<TResult>;
287 combineLatest<T2, T3, T4>(
288 second: Observable<T2> | IPromise<T2>,
289 third: Observable<T3> | IPromise<T3>,
290 fourth: Observable<T4> | IPromise<T4>,
291 ): Observable<[T, T2, T3, T4]>;
292 combineLatest<T2, T3, T4, TResult>(
293 second: Observable<T2> | IPromise<T2>,
294 third: Observable<T3> | IPromise<T3>,
295 fourth: Observable<T4> | IPromise<T4>,
296 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4) => TResult,
297 ): Observable<TResult>;
298 combineLatest<T2, T3, T4, T5>(
299 second: Observable<T2> | IPromise<T2>,
300 third: Observable<T3> | IPromise<T3>,
301 fourth: Observable<T4> | IPromise<T4>,
302 fifth: Observable<T5> | IPromise<T5>,
303 ): Observable<[T, T2, T3, T4, T5]>;
304 combineLatest<T2, T3, T4, T5, TResult>(
305 second: Observable<T2> | IPromise<T2>,
306 third: Observable<T3> | IPromise<T3>,
307 fourth: Observable<T4> | IPromise<T4>,
308 fifth: Observable<T5> | IPromise<T5>,
309 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => TResult,
310 ): Observable<TResult>;
311 combineLatest<TOther, TResult>(
312 souces: Array<Observable<TOther> | IPromise<TOther>>,
313 resultSelector: (firstValue: T, ...otherValues: TOther[]) => TResult,
314 ): Observable<TResult>;
315 withLatestFrom<T2>(second: Observable<T2> | IPromise<T2>): Observable<[T, T2]>;
316 withLatestFrom<T2, TResult>(
317 second: Observable<T2> | IPromise<T2>,
318 resultSelector: (v1: T, v2: T2) => TResult,
319 ): Observable<TResult>;
320 withLatestFrom<T2, T3>(
321 second: Observable<T2> | IPromise<T2>,
322 third: Observable<T3> | IPromise<T3>,
323 ): Observable<[T, T2, T3]>;
324 withLatestFrom<T2, T3, TResult>(
325 second: Observable<T2> | IPromise<T2>,
326 third: Observable<T3> | IPromise<T3>,
327 resultSelector: (v1: T, v2: T2, v3: T3) => TResult,
328 ): Observable<TResult>;
329 withLatestFrom<T2, T3, T4>(
330 second: Observable<T2> | IPromise<T2>,
331 third: Observable<T3> | IPromise<T3>,
332 fourth: Observable<T4> | IPromise<T4>,
333 ): Observable<[T, T2, T3, T4]>;
334 withLatestFrom<T2, T3, T4, TResult>(
335 second: Observable<T2> | IPromise<T2>,
336 third: Observable<T3> | IPromise<T3>,
337 fourth: Observable<T4> | IPromise<T4>,
338 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4) => TResult,
339 ): Observable<TResult>;
340 withLatestFrom<T2, T3, T4, T5>(
341 second: Observable<T2> | IPromise<T2>,
342 third: Observable<T3> | IPromise<T3>,
343 fourth: Observable<T4> | IPromise<T4>,
344 fifth: Observable<T5> | IPromise<T5>,
345 ): Observable<[T, T2, T3, T4, T5]>;
346 withLatestFrom<T2, T3, T4, T5, TResult>(
347 second: Observable<T2> | IPromise<T2>,
348 third: Observable<T3> | IPromise<T3>,
349 fourth: Observable<T4> | IPromise<T4>,
350 fifth: Observable<T5> | IPromise<T5>,
351 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => TResult,
352 ): Observable<TResult>;
353 withLatestFrom<TOther, TResult>(
354 souces: Array<Observable<TOther> | IPromise<TOther>>,
355 resultSelector: (firstValue: T, ...otherValues: TOther[]) => TResult,
356 ): Observable<TResult>;
357 concat(...sources: Array<Observable<T> | IPromise<T>>): Observable<T>;
358 concat(sources: Array<Observable<T> | IPromise<T>>): Observable<T>;
359 concatAll(): T;
360 concatObservable(): Observable<T>; // alias for concatAll
361 concatMap<T2, R>(
362 selector: (value: T, index: number) => Observable<T2>,
363 resultSelector: (value1: T, value2: T2, index: number) => R,
364 ): Observable<R>; // alias for selectConcat
365 concatMap<T2, R>(
366 selector: (value: T, index: number) => IPromise<T2>,
367 resultSelector: (value1: T, value2: T2, index: number) => R,
368 ): Observable<R>; // alias for selectConcat
369 concatMap<R>(selector: (value: T, index: number) => Observable<R>): Observable<R>; // alias for selectConcat
370 concatMap<R>(selector: (value: T, index: number) => IPromise<R>): Observable<R>; // alias for selectConcat
371 concatMap<R>(selector: (value: T, index: number) => R[]): Observable<R>; // alias for selectConcat
372 concatMap<R>(sequence: Observable<R>): Observable<R>; // alias for selectConcat
373 concatMap<R>(sequence: R[]): Observable<R>; // alias for selectConcat
374 merge(maxConcurrent: number): T;
375 merge(other: Observable<T>): Observable<T>;
376 merge(other: IPromise<T>): Observable<T>;
377 mergeAll(): T;
378 mergeObservable(): T; // alias for mergeAll
379 skipUntil<T2>(other: Observable<T2>): Observable<T>;
380 skipUntil<T2>(other: IPromise<T2>): Observable<T>;
381 switch(): T;
382 switchLatest(): T; // alias for switch
383 takeUntil<T2>(other: Observable<T2>): Observable<T>;
384 takeUntil<T2>(other: IPromise<T2>): Observable<T>;
385 zip<T2>(second: Observable<T2> | IPromise<T2>): Observable<[T, T2]>;
386 zip<T2, TResult>(
387 second: Observable<T2> | IPromise<T2>,
388 resultSelector: (v1: T, v2: T2) => TResult,
389 ): Observable<TResult>;
390 zip<T2, T3>(
391 second: Observable<T2> | IPromise<T2>,
392 third: Observable<T3> | IPromise<T3>,
393 ): Observable<[T, T2, T3]>;
394 zip<T2, T3, TResult>(
395 second: Observable<T2> | IPromise<T2>,
396 third: Observable<T3> | IPromise<T3>,
397 resultSelector: (v1: T, v2: T2, v3: T3) => TResult,
398 ): Observable<TResult>;
399 zip<T2, T3, T4>(
400 second: Observable<T2> | IPromise<T2>,
401 third: Observable<T3> | IPromise<T3>,
402 fourth: Observable<T4> | IPromise<T4>,
403 ): Observable<[T, T2, T3, T4]>;
404 zip<T2, T3, T4, TResult>(
405 second: Observable<T2> | IPromise<T2>,
406 third: Observable<T3> | IPromise<T3>,
407 fourth: Observable<T4> | IPromise<T4>,
408 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4) => TResult,
409 ): Observable<TResult>;
410 zip<T2, T3, T4, T5>(
411 second: Observable<T2> | IPromise<T2>,
412 third: Observable<T3> | IPromise<T3>,
413 fourth: Observable<T4> | IPromise<T4>,
414 fifth: Observable<T5> | IPromise<T5>,
415 ): Observable<[T, T2, T3, T4, T5]>;
416 zip<T2, T3, T4, T5, TResult>(
417 second: Observable<T2> | IPromise<T2>,
418 third: Observable<T3> | IPromise<T3>,
419 fourth: Observable<T4> | IPromise<T4>,
420 fifth: Observable<T5> | IPromise<T5>,
421 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => TResult,
422 ): Observable<TResult>;
423 zip<TOther, TResult>(
424 second: Array<Observable<TOther> | IPromise<TOther>>,
425 resultSelector: (left: T, ...right: TOther[]) => TResult,
426 ): Observable<TResult>;
427
428 asObservable(): Observable<T>;
429 dematerialize<TOrigin>(): Observable<TOrigin>;
430 distinctUntilChanged(skipParameter: boolean, comparer: (x: T, y: T) => boolean): Observable<T>;
431 distinctUntilChanged<TValue>(
432 keySelector?: (value: T) => TValue,
433 comparer?: (x: TValue, y: TValue) => boolean,
434 ): Observable<T>;
435 do(observer: Observer<T>): Observable<T>;
436 do(onNext?: (value: T) => void, onError?: (exception: Error) => void, onCompleted?: () => void): Observable<T>;
437 doAction(observer: Observer<T>): Observable<T>; // alias for do
438 doAction(
439 onNext?: (value: T) => void,
440 onError?: (exception: Error) => void,
441 onCompleted?: () => void,
442 ): Observable<T>; // alias for do
443 tap(observer: Observer<T>): Observable<T>; // alias for do
444 tap(onNext?: (value: T) => void, onError?: (exception: Error) => void, onCompleted?: () => void): Observable<T>; // alias for do
445
446 doOnNext(onNext: (value: T) => void, thisArg?: any): Observable<T>;
447 doOnError(onError: (exception: any) => void, thisArg?: any): Observable<T>;
448 doOnCompleted(onCompleted: () => void, thisArg?: any): Observable<T>;
449 tapOnNext(onNext: (value: T) => void, thisArg?: any): Observable<T>;
450 tapOnError(onError: (exception: any) => void, thisArg?: any): Observable<T>;
451 tapOnCompleted(onCompleted: () => void, thisArg?: any): Observable<T>;
452
453 finally(action: () => void): Observable<T>;
454 finallyAction(action: () => void): Observable<T>; // alias for finally
455 ignoreElements(): Observable<T>;
456 materialize(): Observable<Notification<T>>;
457 repeat(repeatCount?: number): Observable<T>;
458 retry(retryCount?: number): Observable<T>;
459 retryWhen<TError>(notifier: (errors: Observable<TError>) => Observable<any>): Observable<T>;
460
461 /**
462 * Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value.
463 * For aggregation behavior with no intermediate results, see Observable.aggregate.
464 * @example
465 * var res = source.scan(function (acc, x) { return acc + x; });
466 * var res = source.scan(function (acc, x) { return acc + x; }, 0);
467 * @param accumulator An accumulator function to be invoked on each element.
468 * @param seed The initial accumulator value.
469 * @returns An observable sequence containing the accumulated values.
470 */
471 scan<TAcc>(
472 accumulator: (acc: TAcc, value: T, index?: number, source?: Observable<TAcc>) => TAcc,
473 seed: TAcc,
474 ): Observable<TAcc>;
475 scan(accumulator: (acc: T, value: T, index?: number, source?: Observable<T>) => T): Observable<T>;
476
477 skipLast(count: number): Observable<T>;
478 startWith(...values: T[]): Observable<T>;
479 startWith(scheduler: IScheduler, ...values: T[]): Observable<T>;
480 takeLast(count: number): Observable<T>;
481 takeLastBuffer(count: number): Observable<T[]>;
482
483 select<TResult>(
484 selector: (value: T, index: number, source: Observable<T>) => TResult,
485 thisArg?: any,
486 ): Observable<TResult>;
487 map<TResult>(
488 selector: (value: T, index: number, source: Observable<T>) => TResult,
489 thisArg?: any,
490 ): Observable<TResult>; // alias for select
491 pluck<TResult>(prop: string): Observable<TResult>;
492 selectMany<TOther, TResult>(
493 selector: (value: T) => Observable<TOther>,
494 resultSelector: (item: T, other: TOther) => TResult,
495 ): Observable<TResult>;
496 selectMany<TOther, TResult>(
497 selector: (value: T) => IPromise<TOther>,
498 resultSelector: (item: T, other: TOther) => TResult,
499 ): Observable<TResult>;
500 selectMany<TResult>(selector: (value: T) => Observable<TResult>): Observable<TResult>;
501 selectMany<TResult>(selector: (value: T) => IPromise<TResult>): Observable<TResult>;
502 selectMany<TResult>(other: Observable<TResult>): Observable<TResult>;
503 selectMany<TResult>(other: IPromise<TResult>): Observable<TResult>;
504 selectMany<TResult>(selector: (value: T) => TResult[]): Observable<TResult>; // alias for selectMany
505 flatMap<TOther, TResult>(
506 selector: (value: T) => Observable<TOther>,
507 resultSelector: (item: T, other: TOther) => TResult,
508 ): Observable<TResult>; // alias for selectMany
509 flatMap<TOther, TResult>(
510 selector: (value: T) => IPromise<TOther>,
511 resultSelector: (item: T, other: TOther) => TResult,
512 ): Observable<TResult>; // alias for selectMany
513 flatMap<TResult>(selector: (value: T) => Observable<TResult>): Observable<TResult>; // alias for selectMany
514 flatMap<TResult>(selector: (value: T) => IPromise<TResult>): Observable<TResult>; // alias for selectMany
515 flatMap<TResult>(other: Observable<TResult>): Observable<TResult>; // alias for selectMany
516 flatMap<TResult>(other: IPromise<TResult>): Observable<TResult>; // alias for selectMany
517 flatMap<TResult>(selector: (value: T) => TResult[]): Observable<TResult>; // alias for selectMany
518
519 /**
520 * Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
521 * @param onNext A transform function to apply to each element; the second parameter of the function represents the index of the source element.
522 * @param onError A transform function to apply when an error occurs in the source sequence.
523 * @param onCompleted A transform function to apply when the end of the source sequence is reached.
524 * @param [thisArg] An optional "this" to use to invoke each transform.
525 * @returns An observable sequence whose elements are the result of invoking the one-to-many transform function corresponding to each notification in the input sequence.
526 */
527 selectManyObserver<T2, T3, T4>(
528 onNext: (value: T, index: number) => Observable<T2>,
529 onError: (exception: any) => Observable<T3>,
530 onCompleted: () => Observable<T4>,
531 thisArg?: any,
532 ): Observable<T2 | T3 | T4>;
533
534 /**
535 * Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
536 * @param onNext A transform function to apply to each element; the second parameter of the function represents the index of the source element.
537 * @param onError A transform function to apply when an error occurs in the source sequence.
538 * @param onCompleted A transform function to apply when the end of the source sequence is reached.
539 * @param [thisArg] An optional "this" to use to invoke each transform.
540 * @returns An observable sequence whose elements are the result of invoking the one-to-many transform function corresponding to each notification in the input sequence.
541 */
542 flatMapObserver<T2, T3, T4>(
543 onNext: (value: T, index: number) => Observable<T2>,
544 onError: (exception: any) => Observable<T3>,
545 onCompleted: () => Observable<T4>,
546 thisArg?: any,
547 ): Observable<T2 | T3 | T4>;
548
549 selectConcat<T2, R>(
550 selector: (value: T, index: number) => Observable<T2>,
551 resultSelector: (value1: T, value2: T2, index: number) => R,
552 ): Observable<R>;
553 selectConcat<T2, R>(
554 selector: (value: T, index: number) => IPromise<T2>,
555 resultSelector: (value1: T, value2: T2, index: number) => R,
556 ): Observable<R>;
557 selectConcat<R>(selector: (value: T, index: number) => Observable<R>): Observable<R>;
558 selectConcat<R>(selector: (value: T, index: number) => IPromise<R>): Observable<R>;
559 selectConcat<R>(sequence: Observable<R>): Observable<R>;
560
561 /**
562 * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
563 * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
564 * @param selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
565 * @param [thisArg] Object to use as this when executing callback.
566 * @returns An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
567 * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
568 */
569 selectSwitch<TResult>(
570 selector: (value: T, index: number, source: Observable<T>) => Observable<TResult>,
571 thisArg?: any,
572 ): Observable<TResult>;
573 /**
574 * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
575 * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
576 * @param selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
577 * @param [thisArg] Object to use as this when executing callback.
578 * @returns An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
579 * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
580 */
581 flatMapLatest<TResult>(
582 selector: (value: T, index: number, source: Observable<T>) => Observable<TResult>,
583 thisArg?: any,
584 ): Observable<TResult>; // alias for selectSwitch
585 /**
586 * Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then
587 * transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
588 * @param selector A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
589 * @param [thisArg] Object to use as this when executing callback.
590 * @since 2.2.28
591 * @returns An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences
592 * and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
593 */
594 switchMap<TResult>(
595 selector: (value: T, index: number, source: Observable<T>) => TResult,
596 thisArg?: any,
597 ): Observable<TResult>; // alias for selectSwitch
598
599 skip(count: number): Observable<T>;
600 skipWhile(predicate: (value: T, index: number, source: Observable<T>) => boolean, thisArg?: any): Observable<T>;
601 take(count: number, scheduler?: IScheduler): Observable<T>;
602 takeWhile(predicate: (value: T, index: number, source: Observable<T>) => boolean, thisArg?: any): Observable<T>;
603 where(predicate: (value: T, index: number, source: Observable<T>) => boolean, thisArg?: any): Observable<T>;
604 filter(predicate: (value: T, index: number, source: Observable<T>) => boolean, thisArg?: any): Observable<T>; // alias for where
605
606 /**
607 * Converts an existing observable sequence to an ES6 Compatible Promise
608 * @example
609 * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
610 * @param promiseCtor The constructor of the promise.
611 * @returns An ES6 compatible promise with the last value from the observable sequence.
612 */
613 toPromise<TPromise extends IPromise<T>>(
614 promiseCtor: {
615 new(
616 resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void,
617 ): TPromise;
618 },
619 ): TPromise;
620 /**
621 * Converts an existing observable sequence to an ES6 Compatible Promise
622 * @example
623 * var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
624 *
625 * // With config
626 * Rx.config.Promise = RSVP.Promise;
627 * var promise = Rx.Observable.return(42).toPromise();
628 * @param [promiseCtor] The constructor of the promise. If not provided, it looks for it in Rx.config.Promise.
629 * @returns An ES6 compatible promise with the last value from the observable sequence.
630 */
631 toPromise(
632 promiseCtor?: {
633 new(
634 resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void,
635 ): IPromise<T>;
636 },
637 ): IPromise<T>;
638
639 // Experimental Flattening
640
641 /**
642 * Performs a exclusive waiting for the first to finish before subscribing to another observable.
643 * Observables that come in between subscriptions will be dropped on the floor.
644 * Can be applied on `Observable<Observable<R>>` or `Observable<IPromise<R>>`.
645 * @since 2.2.28
646 * @returns A exclusive observable with only the results that happen when subscribed.
647 */
648 exclusive<R>(): Observable<R>;
649
650 /**
651 * Performs a exclusive map waiting for the first to finish before subscribing to another observable.
652 * Observables that come in between subscriptions will be dropped on the floor.
653 * Can be applied on `Observable<Observable<I>>` or `Observable<IPromise<I>>`.
654 * @since 2.2.28
655 * @param selector Selector to invoke for every item in the current subscription.
656 * @param [thisArg] An optional context to invoke with the selector parameter.
657 * @returns An exclusive observable with only the results that happen when subscribed.
658 */
659 exclusiveMap<I, R>(
660 selector: (value: I, index: number, source: Observable<I>) => R,
661 thisArg?: any,
662 ): Observable<R>;
663
664 publish(): ConnectableObservable<T>;
665 }
666
667 interface ConnectableObservable<T> extends Observable<T> {
668 connect(): Disposable;
669 }
670
671 interface ObservableStatic {
672 create<T>(subscribe: (observer: Observer<T>) => IDisposable): Observable<T>;
673 create<T>(subscribe: (observer: Observer<T>) => () => void): Observable<T>;
674 create<T>(subscribe: (observer: Observer<T>) => void): Observable<T>;
675 createWithDisposable<T>(subscribe: (observer: Observer<T>) => IDisposable): Observable<T>;
676 defer<T>(observableFactory: () => Observable<T>): Observable<T>;
677 defer<T>(observableFactory: () => IPromise<T>): Observable<T>;
678 empty<T>(scheduler?: IScheduler): Observable<T>;
679
680 /**
681 * This method creates a new Observable sequence from an array object.
682 * @param array An array-like or iterable object to convert to an Observable sequence.
683 * @param mapFn Map function to call on every element of the array.
684 * @param [thisArg] The context to use calling the mapFn if provided.
685 * @param [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
686 */
687 from<T, TResult>(
688 array: T[],
689 mapFn: (value: T, index: number) => TResult,
690 thisArg?: any,
691 scheduler?: IScheduler,
692 ): Observable<TResult>;
693 /**
694 * This method creates a new Observable sequence from an array object.
695 * @param array An array-like or iterable object to convert to an Observable sequence.
696 * @param [mapFn] Map function to call on every element of the array.
697 * @param [thisArg] The context to use calling the mapFn if provided.
698 * @param [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
699 */
700 from<T>(
701 array: T[],
702 mapFn?: (value: T, index: number) => T,
703 thisArg?: any,
704 scheduler?: IScheduler,
705 ): Observable<T>;
706
707 /**
708 * This method creates a new Observable sequence from an array-like object.
709 * @param array An array-like or iterable object to convert to an Observable sequence.
710 * @param mapFn Map function to call on every element of the array.
711 * @param [thisArg] The context to use calling the mapFn if provided.
712 * @param [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
713 */
714 from<T, TResult>(
715 array: { length: number; [index: number]: T },
716 mapFn: (value: T, index: number) => TResult,
717 thisArg?: any,
718 scheduler?: IScheduler,
719 ): Observable<TResult>;
720 /**
721 * This method creates a new Observable sequence from an array-like object.
722 * @param array An array-like or iterable object to convert to an Observable sequence.
723 * @param [mapFn] Map function to call on every element of the array.
724 * @param [thisArg] The context to use calling the mapFn if provided.
725 * @param [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
726 */
727 from<T>(
728 array: { length: number; [index: number]: T },
729 mapFn?: (value: T, index: number) => T,
730 thisArg?: any,
731 scheduler?: IScheduler,
732 ): Observable<T>;
733
734 /**
735 * This method creates a new Observable sequence from an array-like or iterable object.
736 * @param array An array-like or iterable object to convert to an Observable sequence.
737 * @param [mapFn] Map function to call on every element of the array.
738 * @param [thisArg] The context to use calling the mapFn if provided.
739 * @param [scheduler] Optional scheduler to use for scheduling. If not provided, defaults to Scheduler.currentThread.
740 */
741 from<T>(
742 iterable: any,
743 mapFn?: (value: any, index: number) => T,
744 thisArg?: any,
745 scheduler?: IScheduler,
746 ): Observable<T>;
747
748 fromArray<T>(array: T[], scheduler?: IScheduler): Observable<T>;
749 fromArray<T>(array: { length: number; [index: number]: T }, scheduler?: IScheduler): Observable<T>;
750
751 generate<TState, TResult>(
752 initialState: TState,
753 condition: (state: TState) => boolean,
754 iterate: (state: TState) => TState,
755 resultSelector: (state: TState) => TResult,
756 scheduler?: IScheduler,
757 ): Observable<TResult>;
758 never<T>(): Observable<T>;
759
760 /**
761 * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
762 *
763 * @example
764 * var res = Rx.Observable.of(1, 2, 3);
765 * @since 2.2.28
766 * @returns The observable sequence whose elements are pulled from the given arguments.
767 */
768 of<T>(...values: T[]): Observable<T>;
769
770 /**
771 * This method creates a new Observable instance with a variable number of arguments, regardless of number or type of the arguments.
772 * @example
773 * var res = Rx.Observable.ofWithScheduler(Rx.Scheduler.timeout, 1, 2, 3);
774 * @since 2.2.28
775 * @param [scheduler] A scheduler to use for scheduling the arguments.
776 * @returns The observable sequence whose elements are pulled from the given arguments.
777 */
778 ofWithScheduler<T>(scheduler?: IScheduler, ...values: T[]): Observable<T>;
779 range(start: number, count: number, scheduler?: IScheduler): Observable<number>;
780 repeat<T>(value: T, repeatCount?: number, scheduler?: IScheduler): Observable<T>;
781 return<T>(value: T, scheduler?: IScheduler): Observable<T>;
782 /**
783 * @since 2.2.28
784 */
785 just<T>(value: T, scheduler?: IScheduler): Observable<T>; // alias for return
786 returnValue<T>(value: T, scheduler?: IScheduler): Observable<T>; // alias for return
787 throw<T>(exception: Error, scheduler?: IScheduler): Observable<T>;
788 throwException<T>(exception: Error, scheduler?: IScheduler): Observable<T>; // alias for throw
789 throwError<T>(error: Error, scheduler?: IScheduler): Observable<T>; // alias for throw
790
791 catch<T>(sources: Array<IPromise<T>> | Array<Observable<T>>): Observable<T>;
792 catch<T>(...sources: Array<Observable<T>>): Observable<T>;
793 catch<T>(...sources: Array<IPromise<T>>): Observable<T>;
794 catchException<T>(sources: Array<IPromise<T>> | Array<Observable<T>>): Observable<T>; // alias for catch
795 catchException<T>(...sources: Array<Observable<T>>): Observable<T>; // alias for catch
796 catchException<T>(...sources: Array<IPromise<T>>): Observable<T>; // alias for catch
797 catchError<T>(sources: Array<IPromise<T>> | Array<Observable<T>>): Observable<T>; // alias for catch
798 catchError<T>(...sources: Array<Observable<T>>): Observable<T>; // alias for catch
799 catchError<T>(...sources: Array<IPromise<T>>): Observable<T>; // alias for catch
800
801 combineLatest<T, T2>(
802 first: Observable<T> | IPromise<T>,
803 second: Observable<T2> | IPromise<T2>,
804 ): Observable<[T, T2]>;
805 combineLatest<T, T2, TResult>(
806 first: Observable<T> | IPromise<T>,
807 second: Observable<T2> | IPromise<T2>,
808 resultSelector: (v1: T, v2: T2) => TResult,
809 ): Observable<TResult>;
810 combineLatest<T, T2, T3>(
811 first: Observable<T> | IPromise<T>,
812 second: Observable<T2> | IPromise<T2>,
813 third: Observable<T3> | IPromise<T3>,
814 ): Observable<[T, T2, T3]>;
815 combineLatest<T, T2, T3, TResult>(
816 first: Observable<T> | IPromise<T>,
817 second: Observable<T2> | IPromise<T2>,
818 third: Observable<T3> | IPromise<T3>,
819 resultSelector: (v1: T, v2: T2, v3: T3) => TResult,
820 ): Observable<TResult>;
821 combineLatest<T, T2, T3, T4>(
822 first: Observable<T> | IPromise<T>,
823 second: Observable<T2> | IPromise<T2>,
824 third: Observable<T3> | IPromise<T3>,
825 fourth: Observable<T4> | IPromise<T4>,
826 ): Observable<[T, T2, T3, T4]>;
827 combineLatest<T, T2, T3, T4, TResult>(
828 first: Observable<T> | IPromise<T>,
829 second: Observable<T2> | IPromise<T2>,
830 third: Observable<T3> | IPromise<T3>,
831 fourth: Observable<T4> | IPromise<T4>,
832 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4) => TResult,
833 ): Observable<TResult>;
834 combineLatest<T, T2, T3, T4, T5>(
835 first: Observable<T> | IPromise<T>,
836 second: Observable<T2> | IPromise<T2>,
837 third: Observable<T3> | IPromise<T3>,
838 fourth: Observable<T4> | IPromise<T4>,
839 fifth: Observable<T5> | IPromise<T5>,
840 ): Observable<[T, T2, T3, T4, T5]>;
841 combineLatest<T, T2, T3, T4, T5, TResult>(
842 first: Observable<T> | IPromise<T>,
843 second: Observable<T2> | IPromise<T2>,
844 third: Observable<T3> | IPromise<T3>,
845 fourth: Observable<T4> | IPromise<T4>,
846 fifth: Observable<T5> | IPromise<T5>,
847 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => TResult,
848 ): Observable<TResult>;
849 combineLatest<T>(sources: Array<Observable<T> | IPromise<T>>): Observable<T[]>;
850 combineLatest<TOther, TResult>(
851 sources: Array<Observable<TOther> | IPromise<TOther>>,
852 resultSelector: (...otherValues: TOther[]) => TResult,
853 ): Observable<TResult>;
854
855 withLatestFrom<T, T2>(
856 first: Observable<T> | IPromise<T>,
857 second: Observable<T2> | IPromise<T2>,
858 ): Observable<[T, T2]>;
859 withLatestFrom<T, T2, TResult>(
860 first: Observable<T> | IPromise<T>,
861 second: Observable<T2> | IPromise<T2>,
862 resultSelector: (v1: T, v2: T2) => TResult,
863 ): Observable<TResult>;
864 withLatestFrom<T, T2, T3>(
865 first: Observable<T> | IPromise<T>,
866 second: Observable<T2> | IPromise<T2>,
867 third: Observable<T3> | IPromise<T3>,
868 ): Observable<[T, T2, T3]>;
869 withLatestFrom<T, T2, T3, TResult>(
870 first: Observable<T> | IPromise<T>,
871 second: Observable<T2> | IPromise<T2>,
872 third: Observable<T3> | IPromise<T3>,
873 resultSelector: (v1: T, v2: T2, v3: T3) => TResult,
874 ): Observable<TResult>;
875 withLatestFrom<T, T2, T3, T4>(
876 first: Observable<T> | IPromise<T>,
877 second: Observable<T2> | IPromise<T2>,
878 third: Observable<T3> | IPromise<T3>,
879 fourth: Observable<T4> | IPromise<T4>,
880 ): Observable<[T, T2, T3, T4]>;
881 withLatestFrom<T, T2, T3, T4, TResult>(
882 first: Observable<T> | IPromise<T>,
883 second: Observable<T2> | IPromise<T2>,
884 third: Observable<T3> | IPromise<T3>,
885 fourth: Observable<T4> | IPromise<T4>,
886 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4) => TResult,
887 ): Observable<TResult>;
888 withLatestFrom<T, T2, T3, T4, T5>(
889 first: Observable<T> | IPromise<T>,
890 second: Observable<T2> | IPromise<T2>,
891 third: Observable<T3> | IPromise<T3>,
892 fourth: Observable<T4> | IPromise<T4>,
893 fifth: Observable<T5> | IPromise<T5>,
894 ): Observable<[T, T2, T3, T4, T5]>;
895 withLatestFrom<T, T2, T3, T4, T5, TResult>(
896 first: Observable<T> | IPromise<T>,
897 second: Observable<T2> | IPromise<T2>,
898 third: Observable<T3> | IPromise<T3>,
899 fourth: Observable<T4> | IPromise<T4>,
900 fifth: Observable<T5> | IPromise<T5>,
901 resultSelector: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => TResult,
902 ): Observable<TResult>;
903 withLatestFrom<TOther, TResult>(
904 souces: Array<Observable<TOther> | IPromise<TOther>>,
905 resultSelector: (...otherValues: TOther[]) => TResult,
906 ): Observable<TResult>;
907
908 concat<T>(...sources: Array<Observable<T>>): Observable<T>;
909 concat<T>(...sources: Array<IPromise<T>>): Observable<T>;
910 concat<T>(sources: Array<IPromise<T>> | Array<Observable<T>>): Observable<T>;
911 merge<T>(...sources: Array<Observable<T>>): Observable<T>;
912 merge<T>(...sources: Array<IPromise<T>>): Observable<T>;
913 merge<T>(sources: Array<IPromise<T>> | Array<Observable<T>>): Observable<T>;
914 merge<T>(scheduler: IScheduler, ...sources: Array<Observable<T>>): Observable<T>;
915 merge<T>(scheduler: IScheduler, ...sources: Array<IPromise<T>>): Observable<T>;
916 merge<T>(scheduler: IScheduler, sources: Array<IPromise<T>> | Array<Observable<T>>): Observable<T>;
917
918 pairs<T>(obj: { [key: string]: T }, scheduler?: IScheduler): Observable<[string, T]>;
919
920 zip<T1, T2>(
921 first: Observable<T1> | IPromise<T1>,
922 sources: Observable<T2> | IPromise<T2> | Array<Observable<T2> | IPromise<T2>>,
923 ): Observable<[T1, T2]>;
924 zip<T1, T2, TResult>(
925 first: Observable<T1> | IPromise<T1>,
926 sources: Array<Observable<T2> | IPromise<T2>>,
927 resultSelector: (item1: T1, ...right: T2[]) => TResult,
928 ): Observable<TResult>;
929 zip<T1, T2, TResult>(
930 source1: Observable<T1> | IPromise<T1>,
931 source2: Observable<T2> | IPromise<T2>,
932 resultSelector: (item1: T1, item2: T2) => TResult,
933 ): Observable<TResult>;
934 zip<T1, T2, T3>(
935 source1: Observable<T1> | IPromise<T1>,
936 source2: Observable<T2> | IPromise<T2>,
937 source3: Observable<T3> | IPromise<T3>,
938 ): Observable<[T1, T2, T3]>;
939 zip<T1, T2, T3, TResult>(
940 source1: Observable<T1> | IPromise<T1>,
941 source2: Observable<T2> | IPromise<T2>,
942 source3: Observable<T3> | IPromise<T3>,
943 resultSelector: (item1: T1, item2: T2, item3: T3) => TResult,
944 ): Observable<TResult>;
945 zip<T1, T2, T3, T4>(
946 source1: Observable<T1> | IPromise<T1>,
947 source2: Observable<T2> | IPromise<T2>,
948 source3: Observable<T3> | IPromise<T3>,
949 source4: Observable<T4> | IPromise<T4>,
950 ): Observable<[T1, T2, T3, T4]>;
951 zip<T1, T2, T3, T4, TResult>(
952 source1: Observable<T1> | IPromise<T1>,
953 source2: Observable<T2> | IPromise<T2>,
954 source3: Observable<T3> | IPromise<T3>,
955 source4: Observable<T4> | IPromise<T4>,
956 resultSelector: (item1: T1, item2: T2, item3: T3, item4: T4) => TResult,
957 ): Observable<TResult>;
958 zip<T1, T2, T3, T4, T5>(
959 source1: Observable<T1> | IPromise<T1>,
960 source2: Observable<T2> | IPromise<T2>,
961 source3: Observable<T3> | IPromise<T3>,
962 source4: Observable<T4> | IPromise<T4>,
963 source5: Observable<T5> | IPromise<T5>,
964 ): Observable<[T1, T2, T3, T4, T5]>;
965 zip<T1, T2, T3, T4, T5, TResult>(
966 source1: Observable<T1> | IPromise<T1>,
967 source2: Observable<T2> | IPromise<T2>,
968 source3: Observable<T3> | IPromise<T3>,
969 source4: Observable<T4> | IPromise<T4>,
970 source5: Observable<T5> | IPromise<T5>,
971 resultSelector: (item1: T1, item2: T2, item3: T3, item4: T4, item5: T5) => TResult,
972 ): Observable<TResult>;
973 zipArray<T>(...sources: Array<Observable<T> | IPromise<T>>): Observable<T[]>;
974 zipArray<T>(sources: Array<Observable<T> | IPromise<T>>): Observable<T[]>;
975
976 /**
977 * Converts a Promise to an Observable sequence
978 * @param promise An ES6 Compliant promise.
979 * @returns An Observable sequence which wraps the existing promise success and failure.
980 */
981 fromPromise<T>(promise: IPromise<T>): Observable<T>;
982
983 prototype: any;
984 }
985
986 const Observable: ObservableStatic;
987}
988
989// Async
990
991declare namespace Rx {
992 namespace config {
993 /**
994 * Configuration option to determine whether to use native events only
995 */
996 const useNativeEvents: boolean;
997 }
998
999 interface ObservableStatic {
1000 fromCallback: {
1001 // with single result callback without selector
1002 <TResult>(func: (callback: (result: TResult) => any) => any, context?: any): () => Observable<TResult>;
1003 <T1, TResult>(
1004 func: (arg1: T1, callback: (result: TResult) => any) => any,
1005 context?: any,
1006 ): (arg1: T1) => Observable<TResult>;
1007 <T1, T2, TResult>(
1008 func: (arg1: T1, arg2: T2, callback: (result: TResult) => any) => any,
1009 context?: any,
1010 ): (arg1: T1, arg2: T2) => Observable<TResult>;
1011 <T1, T2, T3, TResult>(
1012 func: (arg1: T1, arg2: T2, arg3: T3, callback: (result: TResult) => any) => any,
1013 context?: any,
1014 ): (arg1: T1, arg2: T2, arg3: T3) => Observable<TResult>;
1015 // with any callback with selector
1016 <TCallbackResult, TResult>(
1017 func: (callback: Function) => any,
1018 context: any,
1019 selector: (args: TCallbackResult[]) => TResult,
1020 ): () => Observable<TResult>;
1021 <T1, TCallbackResult, TResult>(
1022 func: (arg1: T1, callback: Function) => any,
1023 context: any,
1024 selector: (args: TCallbackResult[]) => TResult,
1025 ): (arg1: T1) => Observable<TResult>;
1026 <T1, T2, TCallbackResult, TResult>(
1027 func: (arg1: T1, arg2: T2, callback: Function) => any,
1028 context: any,
1029 selector: (args: TCallbackResult[]) => TResult,
1030 ): (arg1: T1, arg2: T2) => Observable<TResult>;
1031 <T1, T2, T3, TCallbackResult, TResult>(
1032 func: (arg1: T1, arg2: T2, arg3: T3, callback: Function) => any,
1033 context: any,
1034 selector: (args: TCallbackResult[]) => TResult,
1035 ): (arg1: T1, arg2: T2, arg3: T3) => Observable<TResult>;
1036 // with any callback without selector
1037 <TResult>(func: (callback: Function) => any, context?: any): () => Observable<TResult>;
1038 <T1, TResult>(
1039 func: (arg1: T1, callback: Function) => any,
1040 context?: any,
1041 ): (arg1: T1) => Observable<TResult>;
1042 <T1, T2, TResult>(
1043 func: (arg1: T1, arg2: T2, callback: Function) => any,
1044 context?: any,
1045 ): (arg1: T1, arg2: T2) => Observable<TResult>;
1046 <T1, T2, T3, TResult>(
1047 func: (arg1: T1, arg2: T2, arg3: T3, callback: Function) => any,
1048 context?: any,
1049 ): (arg1: T1, arg2: T2, arg3: T3) => Observable<TResult>;
1050 // with any function with selector
1051 <TCallbackResult, TResult>(
1052 func: Function,
1053 context: any,
1054 selector: (args: TCallbackResult[]) => TResult,
1055 ): (...args: any[]) => Observable<TResult>;
1056 // with any function without selector
1057 <TResult>(func: Function, context?: any): (...args: any[]) => Observable<TResult>;
1058 };
1059
1060 fromNodeCallback: {
1061 // with single result callback without selector
1062 <T>(func: (callback: (err: any, result: T) => any) => any, context?: any): () => Observable<T>;
1063 <T1, T>(
1064 func: (arg1: T1, callback: (err: any, result: T) => any) => any,
1065 context?: any,
1066 ): (arg1: T1) => Observable<T>;
1067 <T1, T2, T>(
1068 func: (arg1: T1, arg2: T2, callback: (err: any, result: T) => any) => any,
1069 context?: any,
1070 ): (arg1: T1, arg2: T2) => Observable<T>;
1071 <T1, T2, T3, T>(
1072 func: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: T) => any) => any,
1073 context?: any,
1074 ): (arg1: T1, arg2: T2, arg3: T3) => Observable<T>;
1075 // with any callback with selector
1076 <TC, TR>(
1077 func: (callback: Function) => any,
1078 context: any,
1079 selector: (results: TC[]) => TR,
1080 ): () => Observable<TR>;
1081 <T1, TC, TR>(
1082 func: (arg1: T1, callback: Function) => any,
1083 context: any,
1084 selector: (results: TC[]) => TR,
1085 ): (arg1: T1) => Observable<TR>;
1086 <T1, T2, TC, TR>(
1087 func: (arg1: T1, arg2: T2, callback: Function) => any,
1088 context: any,
1089 selector: (results: TC[]) => TR,
1090 ): (arg1: T1, arg2: T2) => Observable<TR>;
1091 <T1, T2, T3, TC, TR>(
1092 func: (arg1: T1, arg2: T2, arg3: T3, callback: Function) => any,
1093 context: any,
1094 selector: (results: TC[]) => TR,
1095 ): (arg1: T1, arg2: T2, arg3: T3) => Observable<TR>;
1096 // with any callback without selector
1097 <TR>(func: (callback: Function) => any, context?: any): () => Observable<TR>;
1098 <T1, TR>(func: (arg1: T1, callback: Function) => any, context?: any): (arg1: T1) => Observable<TR>;
1099 <T1, T2, TR>(
1100 func: (arg1: T1, arg2: T2, callback: Function) => any,
1101 context?: any,
1102 ): (arg1: T1, arg2: T2) => Observable<TR>;
1103 <T1, T2, T3, TR>(
1104 func: (arg1: T1, arg2: T2, arg3: T3, callback: Function) => any,
1105 context?: any,
1106 ): (arg1: T1, arg2: T2, arg3: T3) => Observable<TR>;
1107 // with any function with selector
1108 <TC, T>(func: Function, context: any, selector: (results: TC[]) => T): (...args: any[]) => Observable<T>;
1109 // with any function without selector
1110 <T>(func: Function, context?: any): (...args: any[]) => Observable<T>;
1111 };
1112
1113 fromEvent<T>(
1114 element: ArrayLike<DOMEventTarget> | DOMEventTarget | NodeEventTarget | NativeEventTarget,
1115 eventName: string,
1116 selector?: (...args: any[]) => T,
1117 ): Observable<T>;
1118
1119 fromEventPattern<T>(
1120 addHandler: (handler: Function) => void,
1121 removeHandler: (handler: Function) => void,
1122 selector?: (...args: any[]) => T,
1123 ): Observable<T>;
1124 }
1125
1126 interface NodeEventTarget {
1127 addListener(name: string, cb: (e: any) => any): void;
1128 }
1129
1130 interface NativeEventTarget {
1131 on(name: string, cb: (e: any) => any): void;
1132 off(name: string, cb: (e: any) => any): void;
1133 }
1134
1135 interface DOMEventTarget {
1136 addEventListener(type: string, listener: (e: any) => any, useCapture: boolean): void;
1137 removeEventListener(type: string, listener: (e: any) => any, useCapture: boolean): void;
1138 }
1139}
1140
1141// time
1142
1143declare namespace Rx {
1144 interface TimeInterval<T> {
1145 value: T;
1146 interval: number;
1147 }
1148
1149 interface Timestamp<T> {
1150 value: T;
1151 timestamp: number;
1152 }
1153
1154 interface Observable<T> {
1155 delay(dueTime: Date, scheduler?: IScheduler): Observable<T>;
1156 delay(dueTime: number, scheduler?: IScheduler): Observable<T>;
1157
1158 debounce(dueTime: number, scheduler?: IScheduler): Observable<T>;
1159 throttleWithTimeout(dueTime: number, scheduler?: IScheduler): Observable<T>;
1160 /**
1161 * @deprecated use #debounce or #throttleWithTimeout instead.
1162 */
1163 throttle(dueTime: number, scheduler?: IScheduler): Observable<T>;
1164
1165 timeInterval(scheduler?: IScheduler): Observable<TimeInterval<T>>;
1166
1167 timestamp(scheduler?: IScheduler): Observable<Timestamp<T>>;
1168
1169 sample(interval: number, scheduler?: IScheduler): Observable<T>;
1170 sample<TSample>(sampler: Observable<TSample>, scheduler?: IScheduler): Observable<T>;
1171
1172 timeout(dueTime: Date, other?: Observable<T>, scheduler?: IScheduler): Observable<T>;
1173 timeout(dueTime: number, other?: Observable<T>, scheduler?: IScheduler): Observable<T>;
1174 }
1175
1176 interface ObservableStatic {
1177 interval(period: number, scheduler?: IScheduler): Observable<number>;
1178 interval(dutTime: number, period: number, scheduler?: IScheduler): Observable<number>;
1179 timer(dueTime: number, period: number, scheduler?: IScheduler): Observable<number>;
1180 timer(dueTime: number, scheduler?: IScheduler): Observable<number>;
1181 }
1182}
1183
1184declare module "rx-lite" {
1185 export = Rx;
1186}