Skip to content

Commit

Permalink
chore: deprecate MapTo variants (#6860)
Browse files Browse the repository at this point in the history
* chore: deprecate MapTo variants

Deprecating MapTo variants, as they were only wrappers around the Map variants, and added unnecessary API surface area.

related #6367
resolves #6399

* chore: fix up deprecation messages
  • Loading branch information
benlesh committed Mar 8, 2022
1 parent e48e296 commit 45a22e2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 7 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
8 changes: 7 additions & 1 deletion src/internal/operators/mapTo.ts
@@ -1,8 +1,13 @@
import { OperatorFunction } from '../types';
import { map } from './map';

/** @deprecated To be removed in v9. Use {@link map} instead: `map(() => value)`. */
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. */
/**
* @deprecated Do not specify explicit type parameters. Signatures with type parameters
* that cannot be inferred will be removed in v8. `mapTo` itself will be removed in v9,
* use {@link map} instead: `map(() => value)`.
* */
export function mapTo<T, R>(value: R): OperatorFunction<T, R>;

/**
Expand Down Expand Up @@ -36,6 +41,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
8 changes: 6 additions & 2 deletions src/internal/operators/mergeMapTo.ts
Expand Up @@ -2,12 +2,15 @@ import { OperatorFunction, ObservedValueOf, ObservableInput } from '../types';
import { mergeMap } from './mergeMap';
import { isFunction } from '../util/isFunction';

/* tslint:disable:max-line-length */
/** @deprecated Will be removed in v9. Use {@link mergeMap} instead: `mergeMap(() => result)` */
export function mergeMapTo<O extends ObservableInput<unknown>>(
innerObservable: O,
concurrent?: number
): OperatorFunction<unknown, ObservedValueOf<O>>;
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
/**
* @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,
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R,
Expand Down Expand Up @@ -54,6 +57,7 @@ export function mergeMapTo<T, R, O extends ObservableInput<unknown>>(
* Observables being subscribed to concurrently.
* @return A function that returns an Observable that emits items from the
* given `innerObservable`.
* @deprecated Will be removed in v9. Use {@link mergeMap} instead: `mergeMap(() => result)`
*/
export function mergeMapTo<T, R, O extends ObservableInput<unknown>>(
innerObservable: O,
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)` */

This comment has been minimized.

Copy link
@balazserdeszlogmein

balazserdeszlogmein Mar 18, 2022

Shouldn't the recommended substitution be switchMap?

This comment has been minimized.

Copy link
@jakovljevic-mladen

jakovljevic-mladen Mar 18, 2022

Member

It should, good catch. A PR that fixes this issue is welcome.

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 45a22e2

Please sign in to comment.