Skip to content

Commit

Permalink
refactor: undo accidental change to internal isPromise helper
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Feb 28, 2024
1 parent e375e74 commit 61b3966
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
14 changes: 7 additions & 7 deletions packages/rxjs/spec/util/isPromise-spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { of } from 'rxjs';
import { expect } from 'chai';
import { isThennable } from 'rxjs/internal/Observable';
import { isPromise } from 'rxjs/internal/Observable';

describe('isPromise', () => {
it('should return true for new Promise', () => {
const o = new Promise<any>(() => null);
expect(isThennable(o)).to.be.true;
expect(isPromise(o)).to.be.true;
});

it('should NOT return true for any Observable', () => {
const o: any = of(null);

expect(isThennable(o)).to.be.false;
expect(isPromise(o)).to.be.false;
});

it('should return false for null', () => {
expect(isThennable(null)).to.be.false;
expect(isPromise(null)).to.be.false;
});

it('should return false for undefined', () => {
expect(isThennable(undefined)).to.be.false;
expect(isPromise(undefined)).to.be.false;
});

it('should return false for a number', () => {
expect(isThennable(1)).to.be.false;
expect(isPromise(1)).to.be.false;
});

it('should return false for a string', () => {
expect(isThennable('1')).to.be.false;
expect(isPromise('1')).to.be.false;
});
});
5 changes: 2 additions & 3 deletions packages/rxjs/src/internal/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
CompleteNotification,
ErrorNotification,
NextNotification,
Thennable,
} from './types.js';

/**
Expand Down Expand Up @@ -1231,7 +1230,7 @@ export function getObservableInputType(input: unknown): ObservableInputType {
if (isArrayLike(input)) {
return ObservableInputType.ArrayLike;
}
if (isThennable(input)) {
if (isPromise(input)) {
return ObservableInputType.Promise;
}
if (isAsyncIterable(input)) {
Expand Down Expand Up @@ -1287,7 +1286,7 @@ function isReadableStreamLike<T>(obj: any): obj is ReadableStreamLike<T> {
* Tests to see if the object is "thennable".
* @param value the object to test
*/
export function isThennable(value: any): value is Thennable<any> {
export function isPromise(value: any): value is PromiseLike<any> {
return isFunction(value?.then);
}

Expand Down
6 changes: 1 addition & 5 deletions packages/rxjs/src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,14 @@ export interface Subscribable<T> {
subscribe(observer: Partial<Observer<T>>): Unsubscribable;
}

export interface Thennable<T> {
then(onresolved: ((value: T) => void) | null | undefined, onrejected?: ((reason: any) => void) | null | undefined): void;
}

/**
* Valid types that can be converted to observables.
*/
export type ObservableInput<T> =
| Observable<T>
| InteropObservable<T>
| AsyncIterable<T>
| Thennable<T>
| PromiseLike<T>
| ArrayLike<T>
| Iterable<T>
| ReadableStreamLike<T>;
Expand Down

0 comments on commit 61b3966

Please sign in to comment.