Skip to content

Commit

Permalink
fix: forkJoin POJO signature should match only ObservableInput values (
Browse files Browse the repository at this point in the history
…#6095)

* test: add failing forkJoin POJO test

* fix: tighten forkJoin POJO signature

* chore: update api_guardian

* chore: tighten Record type

* chore: update api_guardian
  • Loading branch information
cartant authored Mar 10, 2021
1 parent e238a15 commit 566427e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion api_guard/dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export declare type Falsy = null | undefined | false | 0 | -0 | 0n | '';

export declare function firstValueFrom<T>(source: Observable<T>): Promise<T>;

export declare function forkJoin(scheduler: null | undefined): Observable<never>;
export declare function forkJoin(sources: readonly []): Observable<never>;
export declare function forkJoin<A extends readonly unknown[]>(sources: readonly [...ObservableInputTuple<A>]): Observable<A>;
export declare function forkJoin<A extends readonly unknown[], R>(sources: readonly [...ObservableInputTuple<A>], resultSelector: (...values: A) => R): Observable<R>;
Expand All @@ -137,7 +138,7 @@ export declare function forkJoin<A extends readonly unknown[], R>(...sourcesAndR
export declare function forkJoin(sourcesObject: {
[K in any]: never;
}): Observable<never>;
export declare function forkJoin<T>(sourcesObject: T): Observable<{
export declare function forkJoin<T extends Record<string, ObservableInput<any>>>(sourcesObject: T): Observable<{
[K in keyof T]: ObservedValueOf<T[K]>;
}>;

Expand Down
6 changes: 6 additions & 0 deletions spec-dtslint/observables/forkJoin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ describe('forkJoin({})', () => {
const obj = { foo: of(1), bar: of('two'), baz: of(false) };
const res = forkJoin(obj); // $ExpectType Observable<{ foo: number; bar: string; baz: boolean; }>
});

it('should reject non-ObservableInput values', () => {
const obj = { answer: 42 };
const res = forkJoin(obj); // $ExpectError

});
});

describe('forkJoin([])', () => {
Expand Down
4 changes: 2 additions & 2 deletions spec/observables/forkJoin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ describe('forkJoin', () => {
it('should have same v5/v6 throwing behavior full argument of null', (done) => {
rxTestScheduler.run(() => {
// It doesn't throw when you pass null
expect(() => forkJoin(null)).not.to.throw();
expect(() => forkJoin(null as any)).not.to.throw();

// It doesn't even throw if you subscribe to forkJoin(null).
expect(() =>
forkJoin(null).subscribe({
forkJoin(null as any).subscribe({
// It sends the error to the subscription.
error: () => done(),
})
Expand Down
8 changes: 6 additions & 2 deletions src/internal/observable/forkJoin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Observable } from '../Observable';
import { ObservedValueOf, ObservableInputTuple } from '../types';
import { ObservedValueOf, ObservableInputTuple, ObservableInput } from '../types';
import { argsArgArrayOrObject } from '../util/argsArgArrayOrObject';
import { innerFrom } from './from';
import { popResultSelector } from '../util/args';
import { OperatorSubscriber } from '../operators/OperatorSubscriber';
import { mapOneOrManyArgs } from '../util/mapOneOrManyArgs';
import { createObject } from '../util/createObject';

export function forkJoin(scheduler: null | undefined): Observable<never>;

// forkJoin([a, b, c])
export function forkJoin(sources: readonly []): Observable<never>;
export function forkJoin<A extends readonly unknown[]>(sources: readonly [...ObservableInputTuple<A>]): Observable<A>;
Expand All @@ -26,7 +28,9 @@ export function forkJoin<A extends readonly unknown[], R>(

// forkJoin({a, b, c})
export function forkJoin(sourcesObject: { [K in any]: never }): Observable<never>;
export function forkJoin<T>(sourcesObject: T): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }>;
export function forkJoin<T extends Record<string, ObservableInput<any>>>(
sourcesObject: T
): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }>;

/**
* Accepts an `Array` of {@link ObservableInput} or a dictionary `Object` of {@link ObservableInput} and returns
Expand Down

0 comments on commit 566427e

Please sign in to comment.