Merge pull request #8672 from benblank/lodash-invoke

add _.invoke to existing lodash definition
This commit is contained in:
Masahiro Wakame
2016-03-26 22:32:43 +09:00
2 changed files with 148 additions and 0 deletions
+82
View File
@@ -4414,6 +4414,88 @@ namespace TestKeyBy {
}
}
//_.invoke
namespace TestInvoke {
let boolArray: boolean[] = [true, false];
let nestedDict: _.Dictionary<Array<number>> = {
a: [0, 1, 2]
}
let numDict: _.Dictionary<number> = {
a: 1,
b: 2,
c: 3,
d: 4
}
let result: string;
result = _.invoke<string>(boolArray, "[1]");
result = _.invoke<string>(boolArray, "[1]", 2);
result = _.invoke<string>(boolArray, [1, "toString"]);
result = _.invoke<string>(boolArray, [1, "toString"], 2);
result = _.invoke<boolean, string>(boolArray, "[1]");
result = _.invoke<boolean, string>(boolArray, "[1]", 2);
result = _.invoke<boolean, string>(boolArray, [1, "toString"]);
result = _.invoke<boolean, string>(boolArray, [1, "toString"], 2);
result = _.invoke<string>(numDict, "a.toString");
result = _.invoke<string>(numDict, "a.toString", 2);
result = _.invoke<string>(numDict, ["a", "toString"]);
result = _.invoke<string>(numDict, ["a", "toString"], 2);
result = _.invoke<number, string>(numDict, "a.toString");
result = _.invoke<number, string>(numDict, "a.toString", 2);
result = _.invoke<number, string>(numDict, ["a", "toString"]);
result = _.invoke<number, string>(numDict, ["a", "toString"], 2);
result = _.invoke<string>(nestedDict, ["a[0].toString"]);
result = _.invoke<string>(nestedDict, ["a[0].toString"], 2);
result = _.invoke<string>(nestedDict, ["a", 0, "toString"]);
result = _.invoke<string>(nestedDict, ["a", 0, "toString"], 2);
result = _.invoke<Array<number>, string>(nestedDict, ["a[0].toString"]);
result = _.invoke<Array<number>, string>(nestedDict, ["a[0].toString"], 2);
result = _.invoke<Array<number>, string>(nestedDict, ["a", 0, "toString"]);
result = _.invoke<Array<number>, string>(nestedDict, ["a", 0, "toString"], 2);
result = _(boolArray).invoke<string>("[1]");
result = _(boolArray).invoke<string>("[1]", 2);
result = _(boolArray).invoke<string>([1, "toString"]);
result = _(boolArray).invoke<string>([1, "toString"], 2);
result = _(numDict).invoke<string>("a.toString");
result = _(numDict).invoke<string>("a.toString", 2);
result = _(numDict).invoke<string>(["a", "toString"]);
result = _(numDict).invoke<string>(["a", "toString"], 2);
result = _(nestedDict).invoke<string>("a[0].toString");
result = _(nestedDict).invoke<string>("a[0].toString", 2);
result = _(nestedDict).invoke<string>(["a", 0, "toString"]);
result = _(nestedDict).invoke<string>(["a", 0, "toString"], 2);
{
let result: _.LoDashExplicitWrapper<string>;
result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper<string>>("[1]");
result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper<string>>("[1]", 2);
result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper<string>>([1, "toString"]);
result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper<string>>([1, "toString"], 2);
result = _(numDict).chain().invoke<_.LoDashExplicitWrapper<string>>("a.toString");
result = _(numDict).chain().invoke<_.LoDashExplicitWrapper<string>>("a.toString", 2);
result = _(numDict).chain().invoke<_.LoDashExplicitWrapper<string>>(["a", "toString"]);
result = _(numDict).chain().invoke<_.LoDashExplicitWrapper<string>>(["a", "toString"], 2);
result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper<string>>("a[0].toString");
result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper<string>>("a[0].toString", 2);
result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper<string>>(["a", 0, "toString"]);
result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper<string>>(["a", 0, "toString"], 2);
}
}
//_.invokeMap
namespace TestInvokeMap {
let numArray = [4, 2, 1, 3]
+66
View File
@@ -7887,6 +7887,72 @@ declare module _ {
): LoDashExplicitObjectWrapper<Dictionary<T>>;
}
//_.invoke
interface LoDashStatic {
/**
* Invokes the method at path of object.
* @param object The object to query.
* @param path The path of the method to invoke.
* @param args The arguments to invoke the method with.
**/
invoke<TObject extends Object, TResult>(
object: TObject,
path: StringRepresentable|StringRepresentable[],
...args: any[]): TResult;
/**
* @see _.invoke
**/
invoke<TValue, TResult>(
object: Dictionary<TValue>|TValue[],
path: StringRepresentable|StringRepresentable[],
...args: any[]): TResult;
/**
* @see _.invoke
**/
invoke<TResult>(
object: any,
path: StringRepresentable|StringRepresentable[],
...args: any[]): TResult;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.invoke
**/
invoke<TResult>(
path: StringRepresentable|StringRepresentable[],
...args: any[]): TResult;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.invoke
**/
invoke<TResult>(
path: StringRepresentable|StringRepresentable[],
...args: any[]): TResult;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.invoke
**/
invoke<TResult>(
path: StringRepresentable|StringRepresentable[],
...args: any[]): TResult;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.invoke
**/
invoke<TResult>(
path: StringRepresentable|StringRepresentable[],
...args: any[]): TResult;
}
//_.invokeMap
interface LoDashStatic {
/**