From d1554b2e55afe5fd9d0ce090b15449e379abedc3 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 23 Oct 2015 23:19:50 +0500 Subject: [PATCH] lodash: signatures of the method _.method changed --- lodash/lodash-tests.ts | 91 ++++++++++++++++++++++++++++++++++++++---- lodash/lodash.d.ts | 43 +++++++++++++++++--- 2 files changed, 120 insertions(+), 14 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c083edd4c..998b1fc5a 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -3788,16 +3788,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 881124328..e029d9ab3 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -9633,40 +9633,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