From a004df7294027795adb7c98dec3fc1073a87c6f2 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 2 Jan 2016 14:33:09 +0500 Subject: [PATCH] lodash: signatures of _.bind have been changed --- lodash/lodash-tests.ts | 87 ++++++++++++++++++++++++++++++++++++++---- lodash/lodash.d.ts | 60 +++++++++++++++++++++-------- 2 files changed, 124 insertions(+), 23 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 77a20e2e2..e138ce731 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5016,16 +5016,87 @@ module TestBefore { } } -var funcBind = function(greeting: string, punctuation: string) { return greeting + ' ' + this.user + punctuation; }; -var funcBound1: (punctuation: string) => any = _.bind(funcBind, { 'name': 'moe' }, 'hi'); -funcBound1('!'); +// _.bind +module TestBind { + type SampleFunc = (a: number, b: string) => boolean; -var funcBound2: (punctuation: string) => any = _(funcBind).bind({ 'name': 'moe' }, 'hi').value(); -funcBound2('!'); + let func: SampleFunc -var addTwoNumbers = function (x: number, y: number) { return x + y }; -var plusTwo = _.bind(addTwoNumbers, null, 2); -plusTwo(100); + { + type SampleResult = (a: number, b: string) => boolean; + + let result: SampleResult; + + result = _.bind(func, any); + result = _.bind(func, any); + } + + { + type SampleResult = (b: string) => boolean; + + let result: SampleResult; + + result = _.bind(func, any, 42); + result = _.bind(func, any, 42); + } + + { + type SampleResult = () => boolean; + + let result: SampleResult; + + result = _.bind(func, any, 42, ''); + result = _.bind(func, any, 42, ''); + } + + { + type SampleResult = (a: number, b: string) => boolean; + + let result: _.LoDashImplicitObjectWrapper; + + result = _(func).bind(any); + } + + { + type SampleResult = (b: string) => boolean; + + let result: _.LoDashImplicitObjectWrapper; + + result = _(func).bind(any, 42); + } + + { + type SampleResult = () => boolean; + + let result: _.LoDashImplicitObjectWrapper; + + result = _(func).bind(any, 42, ''); + } + + { + type SampleResult = (a: number, b: string) => boolean; + + let result: _.LoDashExplicitObjectWrapper; + + result = _(func).chain().bind(any); + } + + { + type SampleResult = (b: string) => boolean; + + let result: _.LoDashExplicitObjectWrapper; + + result = _(func).chain().bind(any, 42); + } + + { + type SampleResult = () => boolean; + + let result: _.LoDashExplicitObjectWrapper; + + result = _(func).chain().bind(any, 42, ''); + } +} // _.bindAll module TestBindAll { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c45ec90ee..5ff18a3dc 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8561,28 +8561,58 @@ declare module _ { } //_.bind - interface LoDashStatic { - /** - * Creates a function that, when called, invokes func with the this binding of thisArg - * and prepends any additional bind arguments to those provided to the bound function. - * @param func The function to bind. - * @param thisArg The this binding of func. - * @param args Arguments to be partially applied. - * @return The new bound function. - **/ - bind( + interface FunctionBind { + placeholder: any; + + ( + func: T, + thisArg: any, + ...partials: any[] + ): TResult; + + ( func: Function, thisArg: any, - ...args: any[]): (...args: any[]) => any; + ...partials: any[] + ): TResult; + } + + interface LoDashStatic { + /** + * Creates a function that invokes func with the this binding of thisArg and prepends any additional _.bind + * arguments to those provided to the bound function. + * + * The _.bind.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for + * partially applied arguments. + * + * Note: Unlike native Function#bind this method does not set the "length" property of bound functions. + * + * @param func The function to bind. + * @param thisArg The this binding of func. + * @param partials The arguments to be partially applied. + * @return Returns the new bound function. + */ + bind: FunctionBind; } interface LoDashImplicitObjectWrapper { /** - * @see _.bind - **/ - bind( + * @see _.bind + */ + bind( thisArg: any, - ...args: any[]): LoDashImplicitObjectWrapper<(...args: any[]) => any>; + ...partials: any[] + ): LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.bind + */ + bind( + thisArg: any, + ...partials: any[] + ): LoDashExplicitObjectWrapper; } //_.bindAll