diff --git a/spec-dtslint/operators/find-spec.ts b/spec-dtslint/operators/find-spec.ts index 5be2b6c6a0..36e986a9e3 100644 --- a/spec-dtslint/operators/find-spec.ts +++ b/spec-dtslint/operators/find-spec.ts @@ -33,18 +33,3 @@ it('should support Boolean properly', () => { // Intentionally weird looking: Because `Observable` is `Observable` and `true` is the truthy bit. const o4 = of(false, false, false, false).pipe(find(Boolean)); // $ExpectType Observable }); - -it('should support this', () => { - const thisArg = { wanted: 5 }; - const a = of(1, 2, 3).pipe(find(function (val) { - const wanted = this.wanted; // $ExpectType number - return val < wanted; - }, thisArg)); -}); - -it('should deprecate thisArg usage', () => { - const a = of(1, 2, 3).pipe(find(Boolean)); // $ExpectNoDeprecation - const b = of(1, 2, 3).pipe(find(Boolean, {})); // $ExpectDeprecation - const c = of(1, 2, 3).pipe(find((value) => Boolean(value))); // $ExpectNoDeprecation - const d = of(1, 2, 3).pipe(find((value) => Boolean(value), {})); // $ExpectDeprecation -}); \ No newline at end of file diff --git a/spec-dtslint/operators/findIndex-spec.ts b/spec-dtslint/operators/findIndex-spec.ts index f159103a49..0d782de6b9 100644 --- a/spec-dtslint/operators/findIndex-spec.ts +++ b/spec-dtslint/operators/findIndex-spec.ts @@ -13,10 +13,6 @@ it('should support a predicate that takes a source ', () => { const o = of('foo', 'bar', 'baz').pipe(findIndex((p, index, source) => p === 'foo')); // $ExpectType Observable }); -it('should support an argument ', () => { - const o = of('foo', 'bar', 'baz').pipe(findIndex(p => p === 'foo', 123)); // $ExpectType Observable -}); - it('should enforce types', () => { const o = of('foo', 'bar', 'baz').pipe(findIndex()); // $ExpectError }); @@ -42,18 +38,3 @@ it('should support inference from a predicate that returns any', () => { } const a = of(1).pipe(findIndex(isTruthy)); // $ExpectType Observable }); - -it('should support this', () => { - const thisArg = { wanted: 5 }; - const a = of(1, 2, 3).pipe(findIndex(function (val) { - const wanted = this.wanted; // $ExpectType number - return val < wanted; - }, thisArg)); -}); - -it('should deprecate thisArg usage', () => { - const a = of(1, 2, 3).pipe(findIndex(Boolean)); // $ExpectNoDeprecation - const b = of(1, 2, 3).pipe(findIndex(Boolean, {})); // $ExpectDeprecation - const c = of(1, 2, 3).pipe(findIndex((value) => Boolean(value))); // $ExpectNoDeprecation - const d = of(1, 2, 3).pipe(findIndex((value) => Boolean(value), {})); // $ExpectDeprecation -}); \ No newline at end of file diff --git a/spec/operators/find-spec.ts b/spec/operators/find-spec.ts index 9dcb3eec66..8ce969ff94 100644 --- a/spec/operators/find-spec.ts +++ b/spec/operators/find-spec.ts @@ -86,24 +86,6 @@ describe('find', () => { }); }); - it('should work with a custom thisArg', () => { - testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { - const e1 = hot(' --a--b---c-|'); - const e1subs = ' ^----! '; - const expected = '-----(b|) '; - - const finder = { - target: 'b', - }; - const predicate = function (this: typeof finder, value: string) { - return value === this.target; - }; - - expectObservable(e1.pipe(find(predicate, finder))).toBe(expected); - expectSubscriptions(e1.subscriptions).toBe(e1subs); - }); - }); - it('should return undefined if element does not match with predicate', () => { testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { const e1 = hot(' --a--b--c--| '); diff --git a/spec/operators/findIndex-spec.ts b/spec/operators/findIndex-spec.ts index 59756a3c15..1b7fae8d71 100644 --- a/spec/operators/findIndex-spec.ts +++ b/spec/operators/findIndex-spec.ts @@ -86,23 +86,6 @@ describe('findIndex', () => { }); }); - it('should work with a custom thisArg', () => { - testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { - const sourceValues = { b: 7 }; - const e1 = hot(' --a--b---c-|', sourceValues); - const e1subs = ' ^----! '; - const expected = '-----(x|) '; - - const predicate = function (this: typeof sourceValues, value: number) { - return value === this.b; - }; - const result = e1.pipe(findIndex(predicate, sourceValues)); - - expectObservable(result).toBe(expected, { x: 1 }); - expectSubscriptions(e1.subscriptions).toBe(e1subs); - }); - }); - it('should return negative index if element does not match with predicate', () => { testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => { const e1 = hot(' --a--b--c--| '); diff --git a/src/internal/operators/find.ts b/src/internal/operators/find.ts index d91a3d8217..01b9e266e5 100644 --- a/src/internal/operators/find.ts +++ b/src/internal/operators/find.ts @@ -5,19 +5,9 @@ import { operate } from '../util/lift'; import { createOperatorSubscriber } from './OperatorSubscriber'; export function find(predicate: BooleanConstructor): OperatorFunction>; -/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */ -export function find( - predicate: (this: A, value: T, index: number, source: Observable) => value is S, - thisArg: A -): OperatorFunction; export function find( predicate: (value: T, index: number, source: Observable) => value is S ): OperatorFunction; -/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */ -export function find( - predicate: (this: A, value: T, index: number, source: Observable) => boolean, - thisArg: A -): OperatorFunction; export function find(predicate: (value: T, index: number, source: Observable) => boolean): OperatorFunction; /** * Emits only the first value emitted by the source Observable that meets some @@ -57,23 +47,14 @@ export function find(predicate: (value: T, index: number, source: Observable< * * @param {function(value: T, index: number, source: Observable): boolean} predicate * A function called with each item to test for condition matching. - * @param {any} [thisArg] An optional argument to determine the value of `this` - * in the `predicate` function. * @return A function that returns an Observable that emits the first item that * matches the condition. */ -export function find( - predicate: (value: T, index: number, source: Observable) => boolean, - thisArg?: any -): OperatorFunction { - return operate(createFind(predicate, thisArg, 'value')); +export function find(predicate: (value: T, index: number, source: Observable) => boolean): OperatorFunction { + return operate(createFind(predicate, 'value')); } -export function createFind( - predicate: (value: T, index: number, source: Observable) => boolean, - thisArg: any, - emit: 'value' | 'index' -) { +export function createFind(predicate: (value: T, index: number, source: Observable) => boolean, emit: 'value' | 'index') { const findIndex = emit === 'index'; return (source: Observable, subscriber: Subscriber) => { let index = 0; @@ -82,7 +63,7 @@ export function createFind( subscriber, (value) => { const i = index++; - if (predicate.call(thisArg, value, i, source)) { + if (predicate(value, i, source)) { subscriber.next(findIndex ? i : value); subscriber.complete(); } diff --git a/src/internal/operators/findIndex.ts b/src/internal/operators/findIndex.ts index 7a9d943cbc..3af7b606f4 100644 --- a/src/internal/operators/findIndex.ts +++ b/src/internal/operators/findIndex.ts @@ -4,13 +4,6 @@ import { operate } from '../util/lift'; import { createFind } from './find'; export function findIndex(predicate: BooleanConstructor): OperatorFunction; -/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */ -export function findIndex(predicate: BooleanConstructor, thisArg: any): OperatorFunction; -/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */ -export function findIndex( - predicate: (this: A, value: T, index: number, source: Observable) => boolean, - thisArg: A -): OperatorFunction; export function findIndex(predicate: (value: T, index: number, source: Observable) => boolean): OperatorFunction; /** @@ -51,14 +44,9 @@ export function findIndex(predicate: (value: T, index: number, source: Observ * * @param {function(value: T, index: number, source: Observable): boolean} predicate * A function called with each item to test for condition matching. - * @param {any} [thisArg] An optional argument to determine the value of `this` - * in the `predicate` function. * @return A function that returns an Observable that emits the index of the * first item that matches the condition. */ -export function findIndex( - predicate: (value: T, index: number, source: Observable) => boolean, - thisArg?: any -): OperatorFunction { - return operate(createFind(predicate, thisArg, 'index')); +export function findIndex(predicate: (value: T, index: number, source: Observable) => boolean): OperatorFunction { + return operate(createFind(predicate, 'index')); }