From c86e9acadc70e3fa48348d791b8a418c178af994 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Tue, 1 Sep 2015 10:39:17 +0500 Subject: [PATCH] lodash: changed _.times() method --- lodash/lodash-tests.ts | 20 +++++++++++++++----- lodash/lodash.d.ts | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 5fee08b29e..eb6efdbeee 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1746,11 +1746,6 @@ class Mage { } } -var mage = new Mage(); -result = _.times(3, <() => number>_.partial(_.random, 1, 6)); -result = _.times(3, function (n: number) { mage.castSpell(n); }); -result = _.times(3, function (n: number) { this.cast(n); }, mage); - result = _.uniqueId('contact_'); result = _.uniqueId(); @@ -1922,3 +1917,18 @@ result = (_(TestMethodOfObject).methodOf(1, 2).value())(['a', '0 result = _.VERSION; result = <_.Support>_.support; result = <_.TemplateSettings>_.templateSettings; + +// _.times +{ + let result: number[]; + result = _.times(42); + result = _(42).times().value(); +} +{ + let testTimesFn: (num: number) => TResult; + let result: TResult[]; + result = _.times(42, testTimesFn); + result = _.times(42, testTimesFn, any); + result = _(42).times(testTimesFn).value(); + result = _(42).times(testTimesFn, any).value(); +} diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 9815f472b4..35b04ae3e7 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8261,16 +8261,39 @@ declare module _ { //_.times interface LoDashStatic { /** - * Executes the callback n times, returning an array of the results of each callback execution. - * The callback is bound to thisArg and invoked with one argument; (index). - * @param n The number of times to execute the callback. - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - **/ + * Invokes the iteratee function n times, returning an array of the results of each invocation. The iteratee is + * bound to thisArg and invoked with one argument; (index). + * + * @param n The number of times to invoke iteratee. + * @param iteratee The function invoked per iteration. + * @param thisArg The this binding of iteratee. + * @return Returns the array of results. + */ times( n: number, - callback: (num: number) => TResult, - context?: any): TResult[]; + iteratee: (num: number) => TResult, + thisArg?: any + ): TResult[]; + + /** + * @see _.times + */ + times(n: number): number[]; + } + + interface LoDashWrapper { + /** + * @see _.times + */ + times( + iteratee: (num: number) => TResult, + thisArgs?: any + ): LoDashArrayWrapper; + + /** + * @see _.times + */ + times(): LoDashArrayWrapper; } //_.uniqueId