diff --git a/api_guard/dist/types/index.d.ts b/api_guard/dist/types/index.d.ts index 0b70c87447..2ab0581fcb 100644 --- a/api_guard/dist/types/index.d.ts +++ b/api_guard/dist/types/index.d.ts @@ -436,9 +436,6 @@ export declare class Observable implements Subscribable { subscribe(observer?: Partial>): Subscription; subscribe(next: (value: T) => void): Subscription; subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription; - toPromise(): Promise; - toPromise(PromiseCtor: typeof Promise): Promise; - toPromise(PromiseCtor: PromiseConstructorLike): Promise; static create: (...args: any[]) => any; } diff --git a/spec-dtslint/Observable-spec.ts b/spec-dtslint/Observable-spec.ts index 991349f89c..c5bf7c4631 100644 --- a/spec-dtslint/Observable-spec.ts +++ b/spec-dtslint/Observable-spec.ts @@ -126,10 +126,6 @@ describe('pipe', () => { const customOperator = () => (a: Observable) => a; const o = of('foo').pipe(customOperator()); // $ExpectType Observable }); - - it('should have proper return type for toPromise', () => { - const o = of('foo').toPromise(); // $ExpectType Promise - }); }); describe('subscribe', () => { diff --git a/spec/operators/toPromise-spec.ts b/spec/operators/toPromise-spec.ts deleted file mode 100644 index bb2f488718..0000000000 --- a/spec/operators/toPromise-spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -/** @prettier */ -import { expect } from 'chai'; -import { of, EMPTY, throwError, config } from 'rxjs'; - -/** @test {toPromise} */ -describe('Observable.toPromise', () => { - it('should convert an Observable to a promise of its last value', (done) => { - of(1, 2, 3) - .toPromise(Promise) - .then((x) => { - expect(x).to.equal(3); - done(); - }); - }); - - it('should convert an empty Observable to a promise of undefined', (done) => { - EMPTY.toPromise(Promise).then((x) => { - expect(x).to.be.undefined; - done(); - }); - }); - - it('should handle errors properly', (done) => { - throwError(() => 'bad') - .toPromise(Promise) - .then( - () => { - done(new Error('should not be called')); - }, - (err: any) => { - expect(err).to.equal('bad'); - done(); - } - ); - }); -}); diff --git a/spec/util/isPromise-spec.ts b/spec/util/isPromise-spec.ts index 0331545fed..5eca957f81 100644 --- a/spec/util/isPromise-spec.ts +++ b/spec/util/isPromise-spec.ts @@ -8,11 +8,6 @@ describe('isPromise', () => { expect(isPromise(o)).to.be.true; }); - it('should return true for a Promise that comes from an Observable', () => { - const o: any = of(null).toPromise(); - expect(isPromise(o)).to.be.true; - }); - it('should NOT return true for any Observable', () => { const o: any = of(null); diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index 4041acb888..ec296be8cf 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -437,46 +437,6 @@ export class Observable implements Subscribable { pipe(...operations: OperatorFunction[]): Observable { return pipeFromArray(operations)(this); } - - /* tslint:disable:max-line-length */ - /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */ - toPromise(): Promise; - /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */ - toPromise(PromiseCtor: typeof Promise): Promise; - /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */ - toPromise(PromiseCtor: PromiseConstructorLike): Promise; - /* tslint:enable:max-line-length */ - - /** - * Subscribe to this Observable and get a Promise resolving on - * `complete` with the last emission (if any). - * - * **WARNING**: Only use this with observables you *know* will complete. If the source - * observable does not complete, you will end up with a promise that is hung up, and - * potentially all of the state of an async function hanging out in memory. To avoid - * this situation, look into adding something like {@link timeout}, {@link take}, - * {@link takeWhile}, or {@link takeUntil} amongst others. - * - * @method toPromise - * @param [promiseCtor] a constructor function used to instantiate - * the Promise - * @return A Promise that resolves with the last value emit, or - * rejects on an error. If there were no emissions, Promise - * resolves with undefined. - * @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise - */ - toPromise(promiseCtor?: PromiseConstructorLike): Promise { - promiseCtor = getPromiseCtor(promiseCtor); - - return new promiseCtor((resolve, reject) => { - let value: T | undefined; - this.subscribe( - (x: T) => (value = x), - (err: any) => reject(err), - () => resolve(value) - ); - }) as Promise; - } } /**