Merge pull request #7447 from chrootsu/lodash-bind

lodash: signatures of _.bind have been changed
This commit is contained in:
Masahiro Wakame
2016-01-10 01:26:13 +09:00
2 changed files with 124 additions and 23 deletions
+79 -8
View File
@@ -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<SampleFunc, SampleResult>(func, any);
result = _.bind<SampleResult>(func, any);
}
{
type SampleResult = (b: string) => boolean;
let result: SampleResult;
result = _.bind<SampleFunc, SampleResult>(func, any, 42);
result = _.bind<SampleResult>(func, any, 42);
}
{
type SampleResult = () => boolean;
let result: SampleResult;
result = _.bind<SampleFunc, SampleResult>(func, any, 42, '');
result = _.bind<SampleResult>(func, any, 42, '');
}
{
type SampleResult = (a: number, b: string) => boolean;
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
result = _(func).bind<SampleResult>(any);
}
{
type SampleResult = (b: string) => boolean;
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
result = _(func).bind<SampleResult>(any, 42);
}
{
type SampleResult = () => boolean;
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
result = _(func).bind<SampleResult>(any, 42, '');
}
{
type SampleResult = (a: number, b: string) => boolean;
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
result = _(func).chain().bind<SampleResult>(any);
}
{
type SampleResult = (b: string) => boolean;
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
result = _(func).chain().bind<SampleResult>(any, 42);
}
{
type SampleResult = () => boolean;
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
result = _(func).chain().bind<SampleResult>(any, 42, '');
}
}
// _.bindAll
module TestBindAll {
+45 -15
View File
@@ -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;
<T extends Function, TResult extends Function>(
func: T,
thisArg: any,
...partials: any[]
): TResult;
<TResult extends Function>(
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<T> {
/**
* @see _.bind
**/
bind(
* @see _.bind
*/
bind<TResult extends Function>(
thisArg: any,
...args: any[]): LoDashImplicitObjectWrapper<(...args: any[]) => any>;
...partials: any[]
): LoDashImplicitObjectWrapper<TResult>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.bind
*/
bind<TResult extends Function>(
thisArg: any,
...partials: any[]
): LoDashExplicitObjectWrapper<TResult>;
}
//_.bindAll