feat: support WeakMap’s in lodash memoize.Cache

This commit is contained in:
Wyatt Johnson
2018-11-02 09:35:15 -06:00
parent f01ba112a9
commit 6448efea6b
2 changed files with 9 additions and 4 deletions
+4 -4
View File
@@ -127,21 +127,21 @@ declare module "../index" {
* @param key The key of the value to remove.
* @return Returns `true` if the entry was removed successfully, else `false`.
*/
delete(key: string): boolean;
delete(key: any): boolean;
/**
* Gets the cached value for `key`.
* @param key The key of the value to get.
* @return Returns the cached value.
*/
get(key: string): any;
get(key: any): any;
/**
* Checks if a cached value for `key` exists.
* @param key The key of the entry to check.
* @return Returns `true` if an entry for `key` exists, else `false`.
*/
has(key: string): boolean;
has(key: any): boolean;
/**
* Sets `value` to `key` of the cache.
@@ -154,7 +154,7 @@ declare module "../index" {
/**
* Removes all key-value entries from the map.
*/
clear(): void;
clear?: () => void;
}
interface MapCacheConstructor {
new (): MapCache;
+5
View File
@@ -3484,6 +3484,11 @@ fp.now(); // $ExpectType number
// $ExpectType MapCache
new _.memoize.Cache();
_.memoize.Cache = WeakMap;
_.memoize.Cache = Map;
const memoizedFn = _.memoize(memoizeFn);
memoizedFn.cache = new WeakMap();
memoizedFn.cache = new Map();
}
// _.overArgs