mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #1574 from david-driscoll/master
lodash.d.ts - (feat): Updated function methods to be generic
This commit is contained in:
@@ -592,6 +592,9 @@ source.addEventListener('message', <_.LoDashObjectWrapper<Function>>_(function()
|
||||
'maxWait': 1000
|
||||
}), false);
|
||||
|
||||
var returnedDebounce = _.throttle(function (a) { return a * 5; }, 5);
|
||||
returnedThrottled(4);
|
||||
|
||||
result = <number>_.defer(function() { console.log('deferred'); });
|
||||
result = <_.LoDashWrapper<number>>_(function() { console.log('deferred'); }).defer();
|
||||
|
||||
@@ -608,15 +611,20 @@ var data = {
|
||||
'curly': { 'name': 'curly', 'age': 60 }
|
||||
};
|
||||
|
||||
var stooge = <Function>_.memoize(function(name: string) { return data[name]; }, _.identity);
|
||||
var stooge = _.memoize(function(name: string) { return data[name]; }, _.identity);
|
||||
stooge('curly');
|
||||
|
||||
stooge['cache']['curly'].name = 'jerome';
|
||||
stooge('curly');
|
||||
|
||||
var initialize = <Function>_.once(function(){ });
|
||||
initialize();
|
||||
var returnedMemoize = _.throttle(function (a) { return a * 5; }, 5);
|
||||
returnedMemoize(4);
|
||||
|
||||
var initialize = _.once(function(){ });
|
||||
initialize();
|
||||
initialize();''
|
||||
var returnedOnce = _.throttle(function (a) { return a * 5; }, 5);
|
||||
returnedOnce(4);
|
||||
|
||||
var greetPartial = function(greeting: string, name: string) { return greeting + ' ' + name; };
|
||||
var hi = <Function>_.partial(greetPartial, 'hi');
|
||||
@@ -638,6 +646,9 @@ jQuery('.interactive').on('click', _.throttle(function() { }, 300000, {
|
||||
'trailing': false
|
||||
}));
|
||||
|
||||
var returnedThrottled = _.throttle(function (a) { return a*5; }, 5);
|
||||
returnedThrottled(4);
|
||||
|
||||
var helloWrap = function(name: string) { return 'hello ' + name; };
|
||||
var helloWrap2 = _.wrap(helloWrap, function(func) {
|
||||
return 'before, ' + func('moe') + ', after';
|
||||
@@ -950,9 +961,9 @@ class Mage {
|
||||
}
|
||||
|
||||
var mage = new Mage();
|
||||
result = <number[]>_.times(3, _.partial(_.random, 1, 6));
|
||||
result = <number[]>_.times(3, function(n: number) { mage.castSpell(n); });
|
||||
result = <number[]>_.times(3, function(n: number) { this.cast(n); }, mage);
|
||||
result = _.times(3, <() => number>_.partial(_.random, 1, 6));
|
||||
result = _.times(3, function(n: number) { mage.castSpell(n); });
|
||||
result = _.times(3, function(n: number) { this.cast(n); }, mage);
|
||||
|
||||
result = <string>_.unescape('Moe, Larry & Curly');
|
||||
|
||||
|
||||
Vendored
+11
-11
@@ -2580,10 +2580,10 @@ declare module _ {
|
||||
* @param options.trailing Specify execution on the trailing edge of the timeout.
|
||||
* @return The new debounced function.
|
||||
**/
|
||||
debounce(
|
||||
func: Function,
|
||||
debounce<T extends Function>(
|
||||
func: T,
|
||||
wait: number,
|
||||
options?: DebounceSettings): Function;
|
||||
options?: DebounceSettings): T;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
@@ -2670,9 +2670,9 @@ declare module _ {
|
||||
* @param resolver Hash function for storing the result of `fn`.
|
||||
* @return Returns the new memoizing function.
|
||||
**/
|
||||
memoize(
|
||||
func: Function,
|
||||
resolver?: (n: any) => string): Function;
|
||||
memoize<T extends Function>(
|
||||
func: T,
|
||||
resolver?: (n: any) => string): T;
|
||||
}
|
||||
|
||||
//_.once
|
||||
@@ -2684,7 +2684,7 @@ declare module _ {
|
||||
* @param func Function to only execute once.
|
||||
* @return The new restricted function.
|
||||
**/
|
||||
once(func: Function): Function;
|
||||
once<T extends Function>(func: T): T;
|
||||
}
|
||||
|
||||
//_.partial
|
||||
@@ -2733,10 +2733,10 @@ declare module _ {
|
||||
* @param options.trailing Specify execution on the trailing edge of the timeout.
|
||||
* @return The new throttled function.
|
||||
**/
|
||||
throttle(
|
||||
func: any,
|
||||
throttle<T extends Function>(
|
||||
func: T,
|
||||
wait: number,
|
||||
options?: ThrottleSettings): Function;
|
||||
options?: ThrottleSettings): T;
|
||||
}
|
||||
|
||||
interface ThrottleSettings {
|
||||
@@ -3764,7 +3764,7 @@ declare module _ {
|
||||
**/
|
||||
times<TResult>(
|
||||
n: number,
|
||||
callback: Function,
|
||||
callback: (num: number) => TResult,
|
||||
context?: any): TResult[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user