diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 30a370b66..9a325f6f8 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5252,16 +5252,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 599973bdd..26581fc8f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8696,28 +8696,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