Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forkJoin POJO signature should match only ObservableInput values #6095

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -165,6 +165,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 @@ -173,7 +174,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<any, ObservableInput<any>>>(sourcesObject: T): Observable<{
cartant marked this conversation as resolved.
Show resolved Hide resolved
[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<any, 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