[underscore] Add generic type for memoize (#34994)

This commit is contained in:
Florian Keller
2019-05-13 19:59:04 +02:00
committed by Nathan Shively-Sanders
parent f832cffd77
commit 353eb17ad6
3 changed files with 18 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/epeli/underscore.string
// Definitions by: Ry Racherbaumer <https://github.com/rygine>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.3
import * as _ from 'underscore';

View File

@@ -1,13 +1,14 @@
// Type definitions for Underscore 1.8
// Project: http://underscorejs.org/
// Definitions by: Boris Yankov <https://github.com/borisyankov>
// Josh Baldwin <https://github.com/jbaldwin>
// Christopher Currens <https://github.com/ccurrens>
// Cassey Lottman <https://github.com/clottman>
// Ard Timmerman <https://github.com/confususs>
// Julian Gonggrijp <https://github.com/jgonggrijp>
// Definitions by: Boris Yankov <https://github.com/borisyankov>,
// Josh Baldwin <https://github.com/jbaldwin>,
// Christopher Currens <https://github.com/ccurrens>,
// Cassey Lottman <https://github.com/clottman>,
// Ard Timmerman <https://github.com/confususs>,
// Julian Gonggrijp <https://github.com/jgonggrijp>,
// Florian Keller <https://github.com/ffflorian>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.3
declare var _: _.UnderscoreStatic;
export = _;
@@ -3447,9 +3448,9 @@ declare module _ {
* @param hashFn Hash function for storing the result of `fn`.
* @return Memoized version of `fn`.
**/
memoize(
fn: Function,
hashFn?: (...args: any[]) => string): Function;
memoize<T = Function>(
fn: T,
hashFn?: (...args: any[]) => string): T;
/**
* Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments,

View File

@@ -285,6 +285,12 @@ var fibonacci = _.memoize(function (n) {
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
});
class MyClass {};
var classMemoized = _.memoize<MyClass>(function (classInstance) {
return new classInstance();
});
var log = _.bind(console.log, console);
_.delay(log, 1000, 'logged later');