Skip to content

Commit

Permalink
remove explicit function overloads for promises
Browse files Browse the repository at this point in the history
  • Loading branch information
bram209 committed Sep 18, 2023
1 parent 78d683b commit 9ca285d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ function createObservable<T>(value: T, makePrimitive: boolean): Observable<T> |
export type MaybePromiseObservable<T> = Observable<MaybePromise<T>>;

export function observable<T>(): MaybePromiseObservable<T | undefined>;
export function observable<T>(value: Promise<T>): MaybePromiseObservable<Promise<T>>;
export function observable<T>(value?: Promise<T>): MaybePromiseObservable<Promise<T> | undefined>;
export function observable<T>(value: T): MaybePromiseObservable<T>;
export function observable<T>(value?: T): MaybePromiseObservable<T | undefined> {
return createObservable(value, /*makePrimitive*/ false);
}

export function observablePrimitive<T>(): ObservablePrimitive<MaybePromise<T | undefined>>;
export function observablePrimitive<T>(value: Promise<T>): ObservablePrimitive<MaybePromise<Promise<T>>>;
export function observablePrimitive<T>(value?: Promise<T>): ObservablePrimitive<MaybePromise<Promise<T>> | undefined>;
export function observablePrimitive<T>(value: T): ObservablePrimitive<MaybePromise<T>>;
export function observablePrimitive<T>(value?: T): ObservablePrimitive<MaybePromise<T | undefined>> {
return createObservable(value, /*makePrimitive*/ true);
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ describe('Promise values', () => {
test('when callback works with promises', async () => {
let resolver: (value: number) => void;
const promise = new Promise<number>((resolve) => (resolver = resolve));
const obs = observable<number>(promise);
const obs = observable(promise);
let didWhen = false;
when(obs, () => {
didWhen = true;
Expand All @@ -2208,7 +2208,7 @@ describe('Promise values', () => {
test('when works with promises', async () => {
let resolver: (value: number) => void;
const promise = new Promise<number>((resolve) => (resolver = resolve));
const obs = observable<number>(promise);
const obs = observable(promise);
let didWhen = false;
when(obs).then(() => {
didWhen = true;
Expand Down Expand Up @@ -2564,7 +2564,7 @@ describe('Locking', () => {
});
describe('Primitive <-> Object', () => {
test('Starting as undefined', () => {
const obs = observable<{ test: string }>(undefined);
const obs = observable<{ test: string } | undefined>(undefined);
expect(obs.get()).toEqual(undefined);
obs.set({ test: 'hi' });
expect(obs.get()).toEqual({ test: 'hi' });
Expand Down

0 comments on commit 9ca285d

Please sign in to comment.