diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index b6a14265f..0921ca4b8 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -4414,6 +4414,88 @@ namespace TestKeyBy { } } +//_.invoke +namespace TestInvoke { + let boolArray: boolean[] = [true, false]; + + let nestedDict: _.Dictionary> = { + a: [0, 1, 2] + } + + let numDict: _.Dictionary = { + a: 1, + b: 2, + c: 3, + d: 4 + } + + let result: string; + + result = _.invoke(boolArray, "[1]"); + result = _.invoke(boolArray, "[1]", 2); + result = _.invoke(boolArray, [1, "toString"]); + result = _.invoke(boolArray, [1, "toString"], 2); + + result = _.invoke(boolArray, "[1]"); + result = _.invoke(boolArray, "[1]", 2); + result = _.invoke(boolArray, [1, "toString"]); + result = _.invoke(boolArray, [1, "toString"], 2); + + result = _.invoke(numDict, "a.toString"); + result = _.invoke(numDict, "a.toString", 2); + result = _.invoke(numDict, ["a", "toString"]); + result = _.invoke(numDict, ["a", "toString"], 2); + + result = _.invoke(numDict, "a.toString"); + result = _.invoke(numDict, "a.toString", 2); + result = _.invoke(numDict, ["a", "toString"]); + result = _.invoke(numDict, ["a", "toString"], 2); + + result = _.invoke(nestedDict, ["a[0].toString"]); + result = _.invoke(nestedDict, ["a[0].toString"], 2); + result = _.invoke(nestedDict, ["a", 0, "toString"]); + result = _.invoke(nestedDict, ["a", 0, "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 = _(boolArray).invoke("[1]"); + result = _(boolArray).invoke("[1]", 2); + result = _(boolArray).invoke([1, "toString"]); + result = _(boolArray).invoke([1, "toString"], 2); + + result = _(numDict).invoke("a.toString"); + result = _(numDict).invoke("a.toString", 2); + result = _(numDict).invoke(["a", "toString"]); + result = _(numDict).invoke(["a", "toString"], 2); + + result = _(nestedDict).invoke("a[0].toString"); + result = _(nestedDict).invoke("a[0].toString", 2); + result = _(nestedDict).invoke(["a", 0, "toString"]); + result = _(nestedDict).invoke(["a", 0, "toString"], 2); + + { + let result: _.LoDashExplicitWrapper; + + result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper>("[1]"); + result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper>("[1]", 2); + result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper>([1, "toString"]); + result = _(boolArray).chain().invoke<_.LoDashExplicitWrapper>([1, "toString"], 2); + + result = _(numDict).chain().invoke<_.LoDashExplicitWrapper>("a.toString"); + result = _(numDict).chain().invoke<_.LoDashExplicitWrapper>("a.toString", 2); + result = _(numDict).chain().invoke<_.LoDashExplicitWrapper>(["a", "toString"]); + result = _(numDict).chain().invoke<_.LoDashExplicitWrapper>(["a", "toString"], 2); + + result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper>("a[0].toString"); + result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper>("a[0].toString", 2); + result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper>(["a", 0, "toString"]); + result = _(nestedDict).chain().invoke<_.LoDashExplicitWrapper>(["a", 0, "toString"], 2); + } +} + //_.invokeMap namespace TestInvokeMap { let numArray = [4, 2, 1, 3] diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 6a380ef45..3253d1ef9 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -7887,6 +7887,72 @@ declare module _ { ): LoDashExplicitObjectWrapper>; } + //_.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( + object: TObject, + path: StringRepresentable|StringRepresentable[], + ...args: any[]): TResult; + + /** + * @see _.invoke + **/ + invoke( + object: Dictionary|TValue[], + path: StringRepresentable|StringRepresentable[], + ...args: any[]): TResult; + + /** + * @see _.invoke + **/ + invoke( + object: any, + path: StringRepresentable|StringRepresentable[], + ...args: any[]): TResult; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.invoke + **/ + invoke( + path: StringRepresentable|StringRepresentable[], + ...args: any[]): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.invoke + **/ + invoke( + path: StringRepresentable|StringRepresentable[], + ...args: any[]): TResult; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.invoke + **/ + invoke( + path: StringRepresentable|StringRepresentable[], + ...args: any[]): TResult; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.invoke + **/ + invoke( + path: StringRepresentable|StringRepresentable[], + ...args: any[]): TResult; + } + //_.invokeMap interface LoDashStatic { /**