Skip to content

Commit

Permalink
fix: operators that ignore input values now use unknown rather than…
Browse files Browse the repository at this point in the history
… `any`, which should resolve issues with eslint no-unsafe-argument (#6738)

* fix: use "unknown" type for operators that ignore input values

These operators ignore the values produced by the source Observable, so
they don't need the dynamic typing that "any" would provide for
accessing the values.  Using "unknown" instead of "any" avoids warnings
from eslint rules like @typescript-eslint/no-unsafe-argument in
application code that uses the operators, and it's also a clearer way to
express that the operators don't know or care what the source type is.

resolves #6536

* fix: update api_guard files to reflect intentional API change
  • Loading branch information
Wyzard256 authored Jan 11, 2022
1 parent 45abd01 commit 67cb317
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions api_guard/dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export declare function concatMap<T, O extends ObservableInput<any>>(project: (v
export declare function concatMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
export declare function concatMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<any, ObservedValueOf<O>>;
export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<any, ObservedValueOf<O>>;
export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function concatMapTo<T, R, O extends ObservableInput<unknown>>(observable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function concatWith<T, A extends readonly unknown[]>(...otherSources: [...ObservableInputTuple<A>]): OperatorFunction<T, T | A[number]>;
Expand Down Expand Up @@ -314,7 +314,7 @@ export declare type Head<X extends readonly any[]> = ((...args: X) => any) exten

export declare function identity<T>(x: T): T;

export declare function ignoreElements(): OperatorFunction<any, never>;
export declare function ignoreElements(): OperatorFunction<unknown, never>;

export declare function iif<T, F>(condition: () => boolean, trueResult: ObservableInput<T>, falseResult: ObservableInput<F>): Observable<T | F>;

Expand All @@ -340,7 +340,7 @@ export declare function lastValueFrom<T>(source: Observable<T>): Promise<T>;
export declare function map<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R>;
export declare function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>;

export declare function mapTo<R>(value: R): OperatorFunction<any, R>;
export declare function mapTo<R>(value: R): OperatorFunction<unknown, R>;
export declare function mapTo<T, R>(value: R): OperatorFunction<T, R>;

export declare function materialize<T>(): OperatorFunction<T, Notification<T> & ObservableNotification<T>>;
Expand All @@ -358,7 +358,7 @@ export declare function mergeMap<T, O extends ObservableInput<any>>(project: (va
export declare function mergeMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined, concurrent?: number): OperatorFunction<T, ObservedValueOf<O>>;
export declare function mergeMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R, concurrent?: number): OperatorFunction<T, R>;

export declare function mergeMapTo<O extends ObservableInput<unknown>>(innerObservable: O, concurrent?: number): OperatorFunction<any, ObservedValueOf<O>>;
export declare function mergeMapTo<O extends ObservableInput<unknown>>(innerObservable: O, concurrent?: number): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function mergeMapTo<T, R, O extends ObservableInput<unknown>>(innerObservable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R, concurrent?: number): OperatorFunction<T, R>;

export declare function mergeScan<T, R>(accumulator: (acc: R, value: T, index: number) => ObservableInput<R>, seed: R, concurrent?: number): OperatorFunction<T, R>;
Expand Down Expand Up @@ -729,8 +729,8 @@ export declare function switchMap<T, O extends ObservableInput<any>>(project: (v
export declare function switchMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
export declare function switchMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<any, ObservedValueOf<O>>;
export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<any, ObservedValueOf<O>>;
export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function switchMapTo<T, R, O extends ObservableInput<unknown>>(observable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function switchScan<T, R, O extends ObservableInput<any>>(accumulator: (acc: R, value: T, index: number) => O, seed: R): OperatorFunction<T, ObservedValueOf<O>>;
Expand Down
14 changes: 7 additions & 7 deletions api_guard/dist/types/operators/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export declare function concatMap<T, O extends ObservableInput<any>>(project: (v
export declare function concatMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
export declare function concatMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<any, ObservedValueOf<O>>;
export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<any, ObservedValueOf<O>>;
export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function concatMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function concatMapTo<T, R, O extends ObservableInput<unknown>>(observable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function concatWith<T, A extends readonly unknown[]>(...otherSources: [...ObservableInputTuple<A>]): OperatorFunction<T, T | A[number]>;
Expand Down Expand Up @@ -144,7 +144,7 @@ export interface GroupByOptionsWithElement<K, E, T> {
element: (value: T) => E;
}

export declare function ignoreElements(): OperatorFunction<any, never>;
export declare function ignoreElements(): OperatorFunction<unknown, never>;

export declare function isEmpty<T>(): OperatorFunction<T, boolean>;

Expand All @@ -157,7 +157,7 @@ export declare function last<T, D = T>(predicate: (value: T, index: number, sour
export declare function map<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R>;
export declare function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>;

export declare function mapTo<R>(value: R): OperatorFunction<any, R>;
export declare function mapTo<R>(value: R): OperatorFunction<unknown, R>;
export declare function mapTo<T, R>(value: R): OperatorFunction<T, R>;

export declare function materialize<T>(): OperatorFunction<T, Notification<T> & ObservableNotification<T>>;
Expand All @@ -175,7 +175,7 @@ export declare function mergeMap<T, O extends ObservableInput<any>>(project: (va
export declare function mergeMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined, concurrent?: number): OperatorFunction<T, ObservedValueOf<O>>;
export declare function mergeMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R, concurrent?: number): OperatorFunction<T, R>;

export declare function mergeMapTo<O extends ObservableInput<unknown>>(innerObservable: O, concurrent?: number): OperatorFunction<any, ObservedValueOf<O>>;
export declare function mergeMapTo<O extends ObservableInput<unknown>>(innerObservable: O, concurrent?: number): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function mergeMapTo<T, R, O extends ObservableInput<unknown>>(innerObservable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R, concurrent?: number): OperatorFunction<T, R>;

export declare function mergeScan<T, R>(accumulator: (acc: R, value: T, index: number) => ObservableInput<R>, seed: R, concurrent?: number): OperatorFunction<T, R>;
Expand Down Expand Up @@ -300,8 +300,8 @@ export declare function switchMap<T, O extends ObservableInput<any>>(project: (v
export declare function switchMap<T, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
export declare function switchMap<T, R, O extends ObservableInput<any>>(project: (value: T, index: number) => O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<any, ObservedValueOf<O>>;
export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<any, ObservedValueOf<O>>;
export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function switchMapTo<O extends ObservableInput<unknown>>(observable: O, resultSelector: undefined): OperatorFunction<unknown, ObservedValueOf<O>>;
export declare function switchMapTo<T, R, O extends ObservableInput<unknown>>(observable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;

export declare function switchScan<T, R, O extends ObservableInput<any>>(accumulator: (acc: R, value: T, index: number) => O, seed: R): OperatorFunction<T, ObservedValueOf<O>>;
Expand Down
4 changes: 2 additions & 2 deletions src/internal/operators/concatMapTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
import { isFunction } from '../util/isFunction';

/* tslint:disable:max-line-length */
export function concatMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<any, ObservedValueOf<O>>;
export function concatMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
export function concatMapTo<O extends ObservableInput<unknown>>(
observable: O,
resultSelector: undefined
): OperatorFunction<any, ObservedValueOf<O>>;
): OperatorFunction<unknown, ObservedValueOf<O>>;
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
export function concatMapTo<T, R, O extends ObservableInput<unknown>>(
observable: O,
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/ignoreElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { noop } from '../util/noop';
* `complete` or `error`, based on which one is called by the source
* Observable.
*/
export function ignoreElements(): OperatorFunction<any, never> {
export function ignoreElements(): OperatorFunction<unknown, never> {
return operate((source, subscriber) => {
source.subscribe(new OperatorSubscriber(subscriber, noop));
});
Expand Down
4 changes: 2 additions & 2 deletions src/internal/operators/mapTo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OperatorFunction } from '../types';
import { map } from './map';

export function mapTo<R>(value: R): OperatorFunction<any, R>;
export function mapTo<R>(value: R): OperatorFunction<unknown, R>;
/** @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. */
export function mapTo<T, R>(value: R): OperatorFunction<T, R>;

Expand Down Expand Up @@ -37,6 +37,6 @@ export function mapTo<T, R>(value: R): OperatorFunction<T, R>;
* @return A function that returns an Observable that emits the given `value`
* every time the source Observable emits.
*/
export function mapTo<R>(value: R): OperatorFunction<any, R> {
export function mapTo<R>(value: R): OperatorFunction<unknown, R> {
return map(() => value);
}
2 changes: 1 addition & 1 deletion src/internal/operators/mergeMapTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isFunction } from '../util/isFunction';
export function mergeMapTo<O extends ObservableInput<unknown>>(
innerObservable: O,
concurrent?: number
): OperatorFunction<any, ObservedValueOf<O>>;
): OperatorFunction<unknown, ObservedValueOf<O>>;
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
export function mergeMapTo<T, R, O extends ObservableInput<unknown>>(
innerObservable: O,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/operators/switchMapTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
import { isFunction } from '../util/isFunction';

/* tslint:disable:max-line-length */
export function switchMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<any, ObservedValueOf<O>>;
export function switchMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
export function switchMapTo<O extends ObservableInput<unknown>>(
observable: O,
resultSelector: undefined
): OperatorFunction<any, ObservedValueOf<O>>;
): OperatorFunction<unknown, ObservedValueOf<O>>;
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
export function switchMapTo<T, R, O extends ObservableInput<unknown>>(
observable: O,
Expand Down

0 comments on commit 67cb317

Please sign in to comment.