Skip to content

Commit f85f509

Browse files
committed
refactor: clean up let binding with early return
1 parent 339ead3 commit f85f509

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ export default function memoize<A extends unknown[], R extends unknown, T extend
2727
return function (this: T, ...args: A) {
2828
const id = hash.apply(this, args)
2929
if (cache.has(id)) return cache.get(id)
30-
let result = fn.apply(this, args)
30+
const result = fn.apply(this, args)
31+
cache.set(id, result)
3132
if (result instanceof Promise) {
3233
// eslint-disable-next-line github/no-then
33-
result = result.catch(error => {
34+
return result.catch(error => {
3435
cache.delete(id)
3536
throw error
36-
}) as R
37+
})
3738
}
38-
cache.set(id, result)
3939
return result
4040
}
4141
}

0 commit comments

Comments
 (0)