From 0814eae6f8175d16a33f6035851e5f0f412a25fc Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sun, 3 Jan 2016 20:05:16 +0500 Subject: [PATCH] lodash: signatures of _.bindKey have been changed --- lodash/lodash-tests.ts | 89 ++++++++++++++++++++++++++++++++++++------ lodash/lodash.d.ts | 65 +++++++++++++++++++++--------- 2 files changed, 123 insertions(+), 31 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 77a20e2e2b..df1ea3f07f 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5065,24 +5065,87 @@ module TestBindAll { } } -var objectBindKey = { - 'name': 'moe', - 'greet': function (greeting: string) { - return greeting + ' ' + this.name; +// _.bindKey +module TestBindKey { + let object: { + foo: (a: number, b: string) => boolean; } -}; -var funcBindKey: Function = _.bindKey(objectBindKey, 'greet', 'hi'); -funcBindKey(); + { + type SampleResult = (a: number, b: string) => boolean; -objectBindKey.greet = function (greeting) { - return greeting + ', ' + this.name + '!'; -}; + let result: SampleResult; -funcBindKey(); + result = _.bindKey(object, 'foo'); + result = _.bindKey(object, 'foo'); + } -funcBindKey = _(objectBindKey).bindKey('greet', 'hi').value(); -funcBindKey(); + { + type SampleResult = (b: string) => boolean; + + let result: SampleResult; + + result = _.bindKey(object, 'foo', 42); + result = _.bindKey(object, 'foo', 42); + } + + { + type SampleResult = () => boolean; + + let result: SampleResult; + + result = _.bindKey(object, 'foo', 42, ''); + result = _.bindKey(object, 'foo', 42, ''); + } + + { + type SampleResult = (a: number, b: string) => boolean; + + let result: _.LoDashImplicitObjectWrapper; + + result = _(object).bindKey('foo'); + } + + { + type SampleResult = (b: string) => boolean; + + let result: _.LoDashImplicitObjectWrapper; + + result = _(object).bindKey('foo', 42); + } + + { + type SampleResult = () => boolean; + + let result: _.LoDashImplicitObjectWrapper; + + result = _(object).bindKey('foo', 42, ''); + } + + { + type SampleResult = (a: number, b: string) => boolean; + + let result: _.LoDashExplicitObjectWrapper; + + result = _(object).chain().bindKey('foo'); + } + + { + type SampleResult = (b: string) => boolean; + + let result: _.LoDashExplicitObjectWrapper; + + result = _(object).chain().bindKey('foo', 42); + } + + { + type SampleResult = () => boolean; + + let result: _.LoDashExplicitObjectWrapper; + + result = _(object).chain().bindKey('foo', 42, ''); + } +} // _.compose module TestCompose { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c45ec90eea..f533e6f1f9 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8620,30 +8620,59 @@ declare module _ { } //_.bindKey + interface FunctionBindKey { + placeholder: any; + + ( + object: T, + key: any, + ...partials: any[] + ): TResult; + + ( + object: Object, + key: any, + ...partials: any[] + ): TResult; + } + interface LoDashStatic { /** - * Creates a function that, when called, invokes the method at object[key] and prepends any - * additional bindKey arguments to those provided to the bound function. This method differs - * from _.bind by allowing bound functions to reference methods that will be redefined or don't - * yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern. - * @param object The object the method belongs to. - * @param key The key of the method. - * @param args Arguments to be partially applied. - * @return The new bound function. - **/ - bindKey( - object: T, - key: string, - ...args: any[]): Function; + * Creates a function that invokes the method at object[key] and prepends any additional _.bindKey arguments + * to those provided to the bound function. + * + * This method differs from _.bind by allowing bound functions to reference methods that may be redefined + * or don’t yet exist. See Peter Michaux’s article for more details. + * + * The _.bindKey.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder + * for partially applied arguments. + * + * @param object The object the method belongs to. + * @param key The key of the method. + * @param partials The arguments to be partially applied. + * @return Returns the new bound function. + */ + bindKey: FunctionBindKey; } interface LoDashImplicitObjectWrapper { /** - * @see _.bindKey - **/ - bindKey( - key: string, - ...args: any[]): LoDashImplicitObjectWrapper; + * @see _.bindKey + */ + bindKey( + key: any, + ...partials: any[] + ): LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.bindKey + */ + bindKey( + key: any, + ...partials: any[] + ): LoDashExplicitObjectWrapper; } //_.compose