From fdb85c2f307fb20458b640de55bb3a9b594a3fbc Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Mon, 17 Aug 2015 20:09:46 +0500 Subject: [PATCH] lodash: added _.attempt() method --- lodash/lodash-tests.ts | 16 +++++++++++++++- lodash/lodash.d.ts | 24 +++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 2cbec6853..8922569da 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -91,6 +91,12 @@ var result: any; var any: any; +interface TResult { + a: number; + b: string; + c: boolean; +} + // _.MapCache var testMapCache: _.MapCache; result = <(key: string) => boolean>testMapCache.delete; @@ -1539,9 +1545,17 @@ result = _(new TestValueIn()).valuesIn().value(); // → [1, 2, 3] /********** -* Utilities * +* Utility * ***********/ +// _.attempt +interface TestAttemptFn { + (): TResult; +} +var testAttempFn: TestAttemptFn; +result = _.attempt(testAttempFn); +result = _(testAttempFn).attempt(); + result = <{ name: string }>_.identity({ 'name': 'moe' }); _.mixin({ diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c088f5459..6146bc97d 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -7614,9 +7614,27 @@ declare module _ { words(str?: string, pattern?: string|RegExp): string[]; } - /************* - * Utilities * - *************/ + /*********** + * Utility * + ***********/ + + //_.attempt + interface LoDashStatic { + /** + * Attempts to invoke func, returning either the result or the caught error object. Any additional arguments + * are provided to func when it’s invoked. + * @param func The function to attempt. + * @return Returns the func result or error object. + */ + attempt(func: (...args: any[]) => TResult): TResult|Error; + } + + interface LoDashObjectWrapper { + /** + * @see _.attempt + */ + attempt(): TResult|Error; + } //_.identity interface LoDashStatic {