Skip to content

Commit 45a22e2

Browse files
authored
chore: deprecate MapTo variants (#6860)
* 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
1 parent e48e296 commit 45a22e2

File tree

8 files changed

+33
-7
lines changed

8 files changed

+33
-7
lines changed

spec-dtslint/operators/concatMapTo-spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ it('should enforce the return type', () => {
6363
it('should produce `Observable<never>` when mapping to an `ObservableInput<never>`', () => {
6464
const o = of(1, 2, 3).pipe(concatMapTo(Promise.reject())); // $ExpectType Observable<never>
6565
});
66+
67+
it('should be deprecated', () => {
68+
const o = of(1, 2, 3).pipe(concatMapTo(of(true))); // $ExpectDeprecation
69+
});

spec-dtslint/operators/mapTo-spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ it('should infer correctly when returning a different type', () => {
1212
it('should enforce types', () => {
1313
const o = of(1, 2, 3).pipe(mapTo()); // $ExpectError
1414
});
15+
16+
it('should be deprecated', () => {
17+
const o = of(1, 2, 3).pipe(mapTo(true)); // $ExpectDeprecation
18+
});

spec-dtslint/operators/mergeMapTo-spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@ it('should enforce types of the concurrent parameter with a resultSelector', ()
7575
it('should produce `Observable<never>` when mapping to an `ObservableInput<never>`', () => {
7676
const o = of(1, 2, 3).pipe(mergeMapTo(Promise.reject())); // $ExpectType Observable<never>
7777
});
78+
79+
it('should be deprecated', () => {
80+
const o = of(1, 2, 3).pipe(mergeMapTo(of(true))); // $ExpectDeprecation
81+
});

spec-dtslint/operators/switchMapTo-spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ it('should enforce the return type', () => {
5858
it('should produce `Observable<never>` when mapping to an `ObservableInput<never>`', () => {
5959
const o = of(1, 2, 3).pipe(switchMapTo(Promise.reject())); // $ExpectType Observable<never>
6060
});
61+
62+
it('should be deprecated', () => {
63+
const o = of(1, 2, 3).pipe(switchMapTo(of(true))); // $ExpectDeprecation
64+
});

src/internal/operators/concatMapTo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { concatMap } from './concatMap';
22
import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
33
import { isFunction } from '../util/isFunction';
44

5-
/* tslint:disable:max-line-length */
5+
/** @deprecated Will be removed in v9. Use {@link concatMap} instead: `concatMap(() => result)` */
66
export function concatMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
77
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
88
export function concatMapTo<O extends ObservableInput<unknown>>(
@@ -14,7 +14,6 @@ export function concatMapTo<T, R, O extends ObservableInput<unknown>>(
1414
observable: O,
1515
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
1616
): OperatorFunction<T, R>;
17-
/* tslint:enable:max-line-length */
1817

1918
/**
2019
* Projects each source value to the same Observable which is merged multiple
@@ -70,6 +69,7 @@ export function concatMapTo<T, R, O extends ObservableInput<unknown>>(
7069
* @return A function that returns an Observable of values merged together by
7170
* joining the passed Observable with itself, one after the other, for each
7271
* value emitted from the source.
72+
* @deprecated Will be removed in v9. Use {@link concatMap} instead: `concatMap(() => result)`
7373
*/
7474
export function concatMapTo<T, R, O extends ObservableInput<unknown>>(
7575
innerObservable: O,

src/internal/operators/mapTo.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { OperatorFunction } from '../types';
22
import { map } from './map';
33

4+
/** @deprecated To be removed in v9. Use {@link map} instead: `map(() => value)`. */
45
export function mapTo<R>(value: R): OperatorFunction<unknown, R>;
5-
/** @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. */
6+
/**
7+
* @deprecated Do not specify explicit type parameters. Signatures with type parameters
8+
* that cannot be inferred will be removed in v8. `mapTo` itself will be removed in v9,
9+
* use {@link map} instead: `map(() => value)`.
10+
* */
611
export function mapTo<T, R>(value: R): OperatorFunction<T, R>;
712

813
/**
@@ -36,6 +41,7 @@ export function mapTo<T, R>(value: R): OperatorFunction<T, R>;
3641
* @param value The value to map each source value to.
3742
* @return A function that returns an Observable that emits the given `value`
3843
* every time the source Observable emits.
44+
* @deprecated To be removed in v9. Use {@link map} instead: `map(() => value)`.
3945
*/
4046
export function mapTo<R>(value: R): OperatorFunction<unknown, R> {
4147
return map(() => value);

src/internal/operators/mergeMapTo.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { OperatorFunction, ObservedValueOf, ObservableInput } from '../types';
22
import { mergeMap } from './mergeMap';
33
import { isFunction } from '../util/isFunction';
44

5-
/* tslint:disable:max-line-length */
5+
/** @deprecated Will be removed in v9. Use {@link mergeMap} instead: `mergeMap(() => result)` */
66
export function mergeMapTo<O extends ObservableInput<unknown>>(
77
innerObservable: O,
88
concurrent?: number
99
): OperatorFunction<unknown, ObservedValueOf<O>>;
10-
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
10+
/**
11+
* @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead.
12+
* Details: https://rxjs.dev/deprecations/resultSelector
13+
*/
1114
export function mergeMapTo<T, R, O extends ObservableInput<unknown>>(
1215
innerObservable: O,
1316
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R,
@@ -54,6 +57,7 @@ export function mergeMapTo<T, R, O extends ObservableInput<unknown>>(
5457
* Observables being subscribed to concurrently.
5558
* @return A function that returns an Observable that emits items from the
5659
* given `innerObservable`.
60+
* @deprecated Will be removed in v9. Use {@link mergeMap} instead: `mergeMap(() => result)`
5761
*/
5862
export function mergeMapTo<T, R, O extends ObservableInput<unknown>>(
5963
innerObservable: O,

src/internal/operators/switchMapTo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { switchMap } from './switchMap';
22
import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
33
import { isFunction } from '../util/isFunction';
44

5-
/* tslint:disable:max-line-length */
5+
/** @deprecated Will be removed in v9. Use {@link mergeMap} instead: `mergeMap(() => result)` */
66
export function switchMapTo<O extends ObservableInput<unknown>>(observable: O): OperatorFunction<unknown, ObservedValueOf<O>>;
77
/** @deprecated The `resultSelector` parameter will be removed in v8. Use an inner `map` instead. Details: https://rxjs.dev/deprecations/resultSelector */
88
export function switchMapTo<O extends ObservableInput<unknown>>(
@@ -14,7 +14,6 @@ export function switchMapTo<T, R, O extends ObservableInput<unknown>>(
1414
observable: O,
1515
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
1616
): OperatorFunction<T, R>;
17-
/* tslint:enable:max-line-length */
1817

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

0 commit comments

Comments
 (0)