Skip to content

Commit

Permalink
chore: deprecate MapTo variants
Browse files Browse the repository at this point in the history
Deprecating MapTo variants, as they were only wrappers around the Map variants, and added unnecessary API surface area.

related ReactiveX#6367
  • Loading branch information
benlesh committed Mar 4, 2022
1 parent 8e0f8cc commit b4b44d1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions spec-dtslint/operators/concatMapTo-spec.ts
Expand Up @@ -63,3 +63,7 @@ it('should enforce the return type', () => {
it('should produce `Observable<never>` when mapping to an `ObservableInput<never>`', () => {
const o = of(1, 2, 3).pipe(concatMapTo(Promise.reject())); // $ExpectType Observable<never>
});

it('should be deprecated', () => {
const o = of(1, 2, 3).pipe(concatMapTo(of(true))); // $ExpectDeprecation
});
4 changes: 4 additions & 0 deletions spec-dtslint/operators/mapTo-spec.ts
Expand Up @@ -12,3 +12,7 @@ it('should infer correctly when returning a different type', () => {
it('should enforce types', () => {
const o = of(1, 2, 3).pipe(mapTo()); // $ExpectError
});

it('should be deprecated', () => {
const o = of(1, 2, 3).pipe(mapTo(true)); // $ExpectDeprecation
});
4 changes: 4 additions & 0 deletions spec-dtslint/operators/mergeMapTo-spec.ts
Expand Up @@ -75,3 +75,7 @@ it('should enforce types of the concurrent parameter with a resultSelector', ()
it('should produce `Observable<never>` when mapping to an `ObservableInput<never>`', () => {
const o = of(1, 2, 3).pipe(mergeMapTo(Promise.reject())); // $ExpectType Observable<never>
});

it('should be deprecated', () => {
const o = of(1, 2, 3).pipe(mergeMapTo(of(true))); // $ExpectDeprecation
});
4 changes: 4 additions & 0 deletions spec-dtslint/operators/switchMapTo-spec.ts
Expand Up @@ -58,3 +58,7 @@ it('should enforce the return type', () => {
it('should produce `Observable<never>` when mapping to an `ObservableInput<never>`', () => {
const o = of(1, 2, 3).pipe(switchMapTo(Promise.reject())); // $ExpectType Observable<never>
});

it('should be deprecated', () => {
const o = of(1, 2, 3).pipe(switchMapTo(of(true))); // $ExpectDeprecation
});
4 changes: 2 additions & 2 deletions src/internal/operators/concatMapTo.ts
Expand Up @@ -2,7 +2,7 @@ import { concatMap } from './concatMap';
import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
import { isFunction } from '../util/isFunction';

/* tslint:disable:max-line-length */
/** @deprecated Will be removed in v9. Use {@link concatMap} instead: `concatMap(() => result)` */
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>>(
Expand All @@ -14,7 +14,6 @@ export function concatMapTo<T, R, O extends ObservableInput<unknown>>(
observable: O,
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
): OperatorFunction<T, R>;
/* tslint:enable:max-line-length */

/**
* Projects each source value to the same Observable which is merged multiple
Expand Down Expand Up @@ -70,6 +69,7 @@ export function concatMapTo<T, R, O extends ObservableInput<unknown>>(
* @return A function that returns an Observable of values merged together by
* joining the passed Observable with itself, one after the other, for each
* value emitted from the source.
* @deprecated Will be removed in v9. Use {@link concatMap} instead: `concatMap(() => result)`
*/
export function concatMapTo<T, R, O extends ObservableInput<unknown>>(
innerObservable: O,
Expand Down
1 change: 1 addition & 0 deletions src/internal/operators/mapTo.ts
Expand Up @@ -36,6 +36,7 @@ export function mapTo<T, R>(value: R): OperatorFunction<T, R>;
* @param value The value to map each source value to.
* @return A function that returns an Observable that emits the given `value`
* every time the source Observable emits.
* @deprecated To be removed in v9. Use {@link map} instead: `map(() => value)`.
*/
export function mapTo<R>(value: R): OperatorFunction<unknown, R> {
return map(() => value);
Expand Down
4 changes: 2 additions & 2 deletions src/internal/operators/switchMapTo.ts
Expand Up @@ -2,7 +2,7 @@ import { switchMap } from './switchMap';
import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
import { isFunction } from '../util/isFunction';

/* tslint:disable:max-line-length */
/** @deprecated Will be removed in v9. Use {@link mergeMap} instead: `mergeMap(() => result)` */
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>>(
Expand All @@ -14,7 +14,6 @@ export function switchMapTo<T, R, O extends ObservableInput<unknown>>(
observable: O,
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
): OperatorFunction<T, R>;
/* tslint:enable:max-line-length */

/**
* Projects each source value to the same Observable which is flattened multiple
Expand Down Expand Up @@ -55,6 +54,7 @@ export function switchMapTo<T, R, O extends ObservableInput<unknown>>(
* `resultSelector`) every time a value is emitted on the source Observable,
* and taking only the values from the most recently projected inner
* Observable.
* @deprecated Will be removed in v9. Use {@link mergeMap} instead: `mergeMap(() => result)`
*/
export function switchMapTo<T, R, O extends ObservableInput<unknown>>(
innerObservable: O,
Expand Down

0 comments on commit b4b44d1

Please sign in to comment.