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

feat: modify cache type to allow generic usage #2947

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eungwang1
Copy link

Current Issue:
The current implementation of cache.get does not support explicit type definitions, which limits type safety and can lead to potential issues with type inference. Here's how it's currently implemented:

const { cache } = useSWRConfig();
const data = cache.get('key'); 

Proposed Changes:
This pull request modifies cache.get to accept generic type parameters, enhancing type safety by allowing developers to specify the expected return type. The modified implementation is as follows:

const { cache } = useSWRConfig();
const data = cache.get<KeyType>('key');

This update ensures better type checking and integration with TypeScript projects, aligning with modern development practices in type-safe applications.

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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.

None yet

1 participant