diff --git a/index.d.ts b/index.d.ts index 2f31856..b999044 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1 @@ -import Observable = require("zen-observable"); -export { Observable }; -export type Observer = ZenObservable.Observer; -export type Subscription = ZenObservable.Subscription; -export type Subscriber = ZenObservable.Subscriber; +export * from "./module"; diff --git a/module.d.ts b/module.d.ts index 6d1e0ee..c06c4d2 100644 --- a/module.d.ts +++ b/module.d.ts @@ -1 +1,58 @@ -export * from "./index"; +export interface Subscription { + closed: boolean; + unsubscribe(): void; +} + +interface SubscriptionObserver { + closed: boolean; + next(value: T): void; + error(errorValue: any): void; + complete(): void; +} + +export interface Observer { + start?(subscription: Subscription): any; + next?(value: T): void; + error?(errorValue: any): void; + complete?(): void; +} + +export type Subscriber = ( + observer: SubscriptionObserver, +) => void | (() => void) | Subscription; + +interface ObservableLike { + subscribe?: Subscriber | undefined; + [Symbol.observable](): Observable | ObservableLike; +} + +export declare class Observable { + constructor(subscriber: Subscriber); + + // 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(instance: Observable, subscriber: Subscriber): undefined; + static apply(instance: Observable, args: IArguments | [Subscriber]): undefined; + + subscribe(observer: Observer): Subscription; + subscribe( + onNext: (value: T) => void, + onError?: (error: any) => void, + onComplete?: () => void, + ): Subscription; + + [Symbol.observable](): Observable; + + forEach(callback: (value: T) => void): Promise; + map(callback: (value: T) => R): Observable; + filter(callback: (value: T) => value is S): Observable; + filter(callback: (value: T) => boolean): Observable; + reduce(callback: (previousValue: T, currentValue: T) => T, initialValue?: T): Observable; + reduce(callback: (previousValue: R, currentValue: T) => R, initialValue?: R): Observable; + flatMap(callback: (value: T) => ObservableLike): Observable; + concat(...observable: Array>): Observable; + + static from(observable: Observable | ObservableLike | ArrayLike): Observable; + static of(...items: R[]): Observable; +} diff --git a/package-lock.json b/package-lock.json index 2bc8a93..29efd88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,6 @@ "version": "1.1.0", "license": "MIT", "dependencies": { - "@types/zen-observable": "0.8.3", "zen-observable": "0.8.15" }, "devDependencies": { @@ -1732,11 +1731,6 @@ "@types/node": "*" } }, - "node_modules/@types/zen-observable": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz", - "integrity": "sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw==" - }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", @@ -4611,11 +4605,6 @@ "@types/node": "*" } }, - "@types/zen-observable": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz", - "integrity": "sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw==" - }, "@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", diff --git a/package.json b/package.json index f881520..f882756 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "MIT", "main": "index.js", "module": "module.js", - "types": "index.d.ts", + "types": "module.d.ts", "repository": { "type": "git", "url": "git+https://github.com/apollographql/zen-observable-ts.git" @@ -20,7 +20,6 @@ "test": "mocha tests/bundle.js" }, "dependencies": { - "@types/zen-observable": "0.8.3", "zen-observable": "0.8.15" }, "devDependencies": {