Skip to content

Commit

Permalink
Add types for Observable.{call,apply}.
Browse files Browse the repository at this point in the history
We implemented these methods explicitly in PR #1, but then PR #105 went
back to compiling `Observable` down to ES5 constructor functions.

In other words, the current implementations of `Observable` (both
CommonJS and ESM) automatically have these static methods, and they work
just like `Function.prototype.{call,apply}`, because `Observable` is
compiled in both cases from a `class` to a constructor function.
  • Loading branch information
benjamn committed Aug 24, 2021
1 parent 8a28432 commit 242b09f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ interface ObservableLike<T> {
export declare class Observable<T> {
constructor(subscriber: Subscriber<T>);

// For backwards compatibility when super(subscriber) is transpiled to
// Observable.call(this, subscriber), which typically happens when the
// Observable class is compiled to ES5 function contructor syntax.
static call<R>(instance: Observable<R>, subscriber: Subscriber<R>): undefined;
static apply<R>(instance: Observable<R>, args: IArguments | [Subscriber<R>]): undefined;

subscribe(observer: Observer<T>): Subscription;
subscribe(
onNext: (value: T) => void,
Expand Down

0 comments on commit 242b09f

Please sign in to comment.