jperasmus / stale-while-revalidate-cache

Storage-agnostic and configurable stale-while-revalidate cache helper for any function, for any JavaScript environment.
MIT License
62 stars 5 forks source link

Update type to reflected that the awaited value is stored #27

Closed andreaspalsson closed 1 year ago

andreaspalsson commented 1 year ago

The types says that the return value of the provided function is stored in the cache. This works fine for non async functions but if a async function is provided this will result in the stored value is a promise and not the value the promise will resolve.

Since the provided function is always awaited the Awaited type can be used to get the resolved value of a promise.

Fixes https://github.com/jperasmus/stale-while-revalidate-cache/issues/26

Also update the type in the readme example so it doesn't generate an error, but maybe it should just be removed since it will be correctly inferred by TypeScript.