lodash: added _.attempt() method

This commit is contained in:
Ilya Mochalov
2015-08-20 01:35:57 +05:00
parent bb45306d0f
commit fdb85c2f30
2 changed files with 36 additions and 4 deletions
+15 -1
View File
@@ -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 = <number[]>_(new TestValueIn()).valuesIn<number>().value();
// → [1, 2, 3]
/**********
* Utilities *
* Utility *
***********/
// _.attempt
interface TestAttemptFn {
(): TResult;
}
var testAttempFn: TestAttemptFn;
result = <TResult|Error>_.attempt<TResult>(testAttempFn);
result = <TResult|Error>_(testAttempFn).attempt<TResult>();
result = <{ name: string }>_.identity({ 'name': 'moe' });
_.mixin({
+21 -3
View File
@@ -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 its invoked.
* @param func The function to attempt.
* @return Returns the func result or error object.
*/
attempt<TResult>(func: (...args: any[]) => TResult): TResult|Error;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.attempt
*/
attempt<TResult>(): TResult|Error;
}
//_.identity
interface LoDashStatic {