Maintain types for memoized functions
This commit is contained in:
1 parent
faa12537e4
commit
63876025d2
6 files changed
+10
-9
No files matched your search
@@ -20,9 +20,10 @@ function getKey(obj): string {
|
||||
return k;
|
||||
}
|
||||
|
||||
export default function memoize(func): Function {
|
||||
return (...args) => {
|
||||
const key = JSON.stringify(args.map(getKey)) + getKey(func);
|
||||
export default function memoize<T extends Function>(func: T): T {
|
||||
const funcKey = getKey(func);
|
||||
return ((...args) => {
|
||||
const key = JSON.stringify(args.map(getKey)) + funcKey;
|
||||
|
||||
if (cache1.has(key)) return cache1.get(key);
|
||||
|
||||
@@ -31,7 +32,7 @@ export default function memoize(func): Function {
|
||||
else r = func(...args);
|
||||
cache1.set(key, r);
|
||||
return r;
|
||||
};
|
||||
}) as any;
|
||||
}
|
||||
|
||||
const interval = setInterval(() => {
|
||||
|
||||
Reference in new issue
Block a user