diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 93dd23ef7..5b60863f6 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -385,7 +385,7 @@ result = _.where(stoogesCombined, { 'quotes': ['Poifect!'] } var saves = ['profile', 'settings']; var asyncSave = (obj) => obj.done(); -var done = _.after(saves.length, function() { +var done: Function = _.after(saves.length, function() { console.log('Done saving!'); }); @@ -396,7 +396,7 @@ _.forEach(saves, function(type) { var funcBind = function (greeting) { return greeting + ' ' + this.name }; // need a second var otherwise typescript thinks func signature is the above func type, // instead of the newly returned _bind => func type. -var funcBind2 = _.bind(funcBind, { 'name': 'moe' }, 'hi'); +var funcBind2: () => any = _.bind(funcBind, { 'name': 'moe' }, 'hi'); funcBind2(); var view = { @@ -404,7 +404,7 @@ var view = { 'onClick': function() { console.log('clicked ' + this.label); } }; -_.bindAll(view); +view = _.bindAll(view); jQuery('#docs').on('click', view.onClick); var objectBindKey = { @@ -414,7 +414,7 @@ var objectBindKey = { } }; -var funcBindKey = _.bindKey(object, 'greet', 'hi'); +var funcBindKey: Function = _.bindKey(object, 'greet', 'hi'); funcBindKey(); objectBindKey.greet = function(greeting) { @@ -436,10 +436,12 @@ var greet = function(formatted) { return 'Hiya ' + formatted + '!'; }; -var welcome = _.compose(greet, format); +var welcome: Function = _.compose(greet, format); welcome('curly'); - +var createCallbackObj = { name: 'Joe' }; +var pluckCallback: () => any = _.createCallback('name'); +var whereCallback: () => boolean = _.createCallback(createCallbackObj); //////////////////////////////////////////////////////////////////////////////////////// diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 368dafaf4..fa6a60e3e 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1726,6 +1726,7 @@ declare module _ { * @param object The object to bind and assign the bound methods to. * @param methodNames The object method names to bind, specified as individual method names * or arrays of method names. + * @return object **/ export function bindAll( object: any, @@ -1756,8 +1757,28 @@ declare module _ { **/ export function compose(...funcs: Function[]): Function; + /** + * Produces a callback bound to an optional thisArg. If func is a property name the created + * callback will return the property value for a given element. If func is an object the created + * callback will return true for elements that contain the equivalent object properties, + * otherwise it will return false. + * @param func The value to convert to a callback. + * @param thisArg The this binding of the created callback. + * @param argCount The number of arguments the callback accepts. + * @return A callback function. + **/ + export function createCallback( + func: string, + thisArg?: any, + argCount?: number): () => any; - + /** + * @see _.createCallback + **/ + export function createCallback( + func: Dictionary, + thisArg?: any, + argCount?: number): () => boolean;