Skip to content
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

Improve types to reflect key-making functions may return undefined #627

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

benjamn
Copy link
Owner

@benjamn benjamn commented Nov 29, 2023

Returning undefined from makeCacheKey is the recommended technique for efficiently opting out of caching for particular combinations of input arguments, so that possibility should be reflected in the TypeScript types for the various functions that handle keys.

@benjamn benjamn self-assigned this Nov 29, 2023
Comment on lines 87 to +91
// This property is equivalent to the makeCacheKey function provided in the
// OptimisticWrapOptions, or (if no options.makeCacheKey function is provided)
// a default implementation of makeCacheKey.
makeCacheKey: (...args: TKeyArgs) => TCacheKey;
// a default implementation of makeCacheKey. This function is also exposed as
// optimistic.options.makeCacheKey, somewhat redundantly.
makeCacheKey: (...args: TKeyArgs) => TCacheKey | undefined;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this optimistic.makeCacheKey function could/should be removed in v1.0, since it's redundant with optimistic.options.makeCacheKey, but I didn't want any breaking changes in this PR.

@benjamn benjamn merged commit 701dcdd into main Nov 29, 2023
5 checks passed
@benjamn benjamn deleted the ts-allow-undefined-keys branch November 29, 2023 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant