-
-
Notifications
You must be signed in to change notification settings - Fork 57
TypeScript - Fix the cache type #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
index.d.ts
Outdated
@@ -33,7 +33,7 @@ export interface Options< | |||
* | |||
* @default new Map() | |||
*/ | |||
readonly cache?: CacheStorage<CacheKeyType, ReturnType>; | |||
readonly cache?: CacheStorage<CacheKeyType, { data: ReturnType; maxAge?: number; }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is maxAge
optional? It is not being set conditionally in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you aren't using the maxAge
option then this value is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this definition, you're basically saying that maxAge
may be sometimes provided to the underlying API. This is, however, not the case. maxAge
is always set, disregarding of whether you use it or not.
When you implement a custom cache storage you don't actually have to use the maxAge
value, it is however, always there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for that explanation @BendingBender! Changing maxAge
to required.
@sindresorhus Thanks for adding types to your repos!
I believe the
cache
type needs to include thedata
, otherwise this isn't possible: