diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 19f05bd54..d119193ee 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -4095,16 +4095,91 @@ module TestMatches { } // _.method -class TestMethod { - a = { - b: (a1: number, a2: number) => a1 + a2 +module TestMethod { + { + let result: (object: any) => {a: string}; + + result = _.method<{a: string}>('a.0'); + result = _.method<{a: string}>('a.0', any); + result = _.method<{a: string}>('a.0', any, any); + result = _.method<{a: string}>('a.0', any, any, any); + + result = _.method<{a: string}>(['a', 0]); + result = _.method<{a: string}>(['a', 0], any); + result = _.method<{a: string}>(['a', 0], any, any); + result = _.method<{a: string}>(['a', 0], any, any, any); + } + + { + let result: (object: {a: string}) => {b: string}; + + result = _.method<{a: string}, {b: string}>('a.0'); + result = _.method<{a: string}, {b: string}>('a.0', any); + result = _.method<{a: string}, {b: string}>('a.0', any, any); + result = _.method<{a: string}, {b: string}>('a.0', any, any, any); + + result = _.method<{a: string}, {b: string}>(['a', 0]); + result = _.method<{a: string}, {b: string}>(['a', 0], any); + result = _.method<{a: string}, {b: string}>(['a', 0], any, any); + result = _.method<{a: string}, {b: string}>(['a', 0], any, any, any); + } + + { + let result: _.LoDashImplicitObjectWrapper<(object: any) => {a: string}>; + + result = _('a.0').method<{a: string}>(); + result = _('a.0').method<{a: string}>(any); + result = _('a.0').method<{a: string}>(any, any); + result = _('a.0').method<{a: string}>(any, any, any); + + result = _(['a', 0]).method<{a: string}>(); + result = _(['a', 0]).method<{a: string}>(any); + result = _(['a', 0]).method<{a: string}>(any, any); + result = _(['a', 0]).method<{a: string}>(any, any, any); + } + + { + let result: _.LoDashImplicitObjectWrapper<(object: {a: string}) => {b: string}>; + + result = _('a.0').method<{a: string}, {b: string}>(); + result = _('a.0').method<{a: string}, {b: string}>(any); + result = _('a.0').method<{a: string}, {b: string}>(any, any); + result = _('a.0').method<{a: string}, {b: string}>(any, any, any); + + result = _(['a', 0]).method<{a: string}, {b: string}>(); + result = _(['a', 0]).method<{a: string}, {b: string}>(any); + result = _(['a', 0]).method<{a: string}, {b: string}>(any, any); + result = _(['a', 0]).method<{a: string}, {b: string}>(any, any, any); + } + + { + let result: _.LoDashExplicitObjectWrapper<(object: any) => {a: string}>; + + result = _('a.0').chain().method<{a: string}>(); + result = _('a.0').chain().method<{a: string}>(any); + result = _('a.0').chain().method<{a: string}>(any, any); + result = _('a.0').chain().method<{a: string}>(any, any, any); + + result = _(['a', 0]).chain().method<{a: string}>(); + result = _(['a', 0]).chain().method<{a: string}>(any); + result = _(['a', 0]).chain().method<{a: string}>(any, any); + result = _(['a', 0]).chain().method<{a: string}>(any, any, any); + } + + { + let result: _.LoDashExplicitObjectWrapper<(object: {a: string}) => {b: string}>; + + result = _('a.0').chain().method<{a: string}, {b: string}>(); + result = _('a.0').chain().method<{a: string}, {b: string}>(any); + result = _('a.0').chain().method<{a: string}, {b: string}>(any, any); + result = _('a.0').chain().method<{a: string}, {b: string}>(any, any, any); + + result = _(['a', 0]).chain().method<{a: string}, {b: string}>(); + result = _(['a', 0]).chain().method<{a: string}, {b: string}>(any); + result = _(['a', 0]).chain().method<{a: string}, {b: string}>(any, any); + result = _(['a', 0]).chain().method<{a: string}, {b: string}>(any, any, any); } } -var TestMethodObject = new TestMethod(); -result = (_.method('a.b', 1, 2))(TestMethodObject); -result = (_.method(['a', 'b'], 1, 2))(TestMethodObject); -result = (_('a.b').method(1, 2).value())(TestMethodObject); -result = (_(['a', 'b']).method(1, 2).value())(TestMethodObject); // _.methodOf class TestMethodOf { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 87aed7226..59deecd52 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -9751,40 +9751,71 @@ declare module _ { /** * Creates a function that invokes the method at path on a given object. Any additional arguments are provided * to the invoked method. + * * @param path The path of the method to invoke. * @param args The arguments to invoke the method with. * @return Returns the new function. */ - method(path: string, ...args: any[]): (object: any) => TResult; + method( + path: string|StringRepresentable[], + ...args: any[] + ): (object: TObject) => TResult; /** * @see _.method */ - method(path: any[], ...args: any[]): (object: any) => TResult; + method( + path: string|StringRepresentable[], + ...args: any[] + ): (object: any) => TResult; } interface LoDashImplicitWrapper { /** * @see _.method */ - method(...args: any[]): LoDashImplicitWrapper<(object: any) => TResult>; + method(...args: any[]): LoDashImplicitObjectWrapper<(object: TObject) => TResult>; /** * @see _.method */ - method(...args: any[]): LoDashImplicitWrapper<(object: any) => TResult>; + method(...args: any[]): LoDashImplicitObjectWrapper<(object: any) => TResult>; } interface LoDashImplicitArrayWrapper { /** * @see _.method */ - method(...args: any[]): LoDashImplicitWrapper<(object: any) => TResult>; + method(...args: any[]): LoDashImplicitObjectWrapper<(object: TObject) => TResult>; /** * @see _.method */ - method(...args: any[]): LoDashImplicitWrapper<(object: any) => TResult>; + method(...args: any[]): LoDashImplicitObjectWrapper<(object: any) => TResult>; + } + + interface LoDashExplicitWrapper { + /** + * @see _.method + */ + method(...args: any[]): LoDashExplicitObjectWrapper<(object: TObject) => TResult>; + + /** + * @see _.method + */ + method(...args: any[]): LoDashExplicitObjectWrapper<(object: any) => TResult>; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.method + */ + method(...args: any[]): LoDashExplicitObjectWrapper<(object: TObject) => TResult>; + + /** + * @see _.method + */ + method(...args: any[]): LoDashExplicitObjectWrapper<(object: any) => TResult>; } //_.methodOf