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

cache-manager - add named return type to createCache #924

Merged
merged 6 commits into from
Dec 6, 2024

Conversation

PoOwAa
Copy link
Contributor

@PoOwAa PoOwAa commented Dec 6, 2024

Please check if the PR fulfills these requirements

  • Followed the Contributing guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Solves #923

This PR introduces a named return type, Cache, for the createCache() method. This type explicitly defines the structure of the cache instance, enabling:
Improved type inference and autocomplete in TypeScript.
Easier integration with frameworks like NestJS by allowing direct reference to the Cache type.
Stronger type guarantees, ensuring compatibility with future updates.

Does this PR introduce a breaking change?
No. The changes are fully backward compatible. The new type definition is an explicit representation of the existing inferred type, so no runtime behavior is affected.

Code example

import { Cache, createCache } from 'cache-manager';

const cache: Cache = createCache();

cache.set('key', 'value', 60).then(() => {
  cache.get<string>('key').then((value) => {
    console.log(value); // Outputs: 'value'
  });
});

@jaredwray
Copy link
Owner

@PoOwAa thanks so much for the pull request!

@jaredwray jaredwray merged commit 8ea2b07 into jaredwray:main Dec 6, 2024
3 checks passed
@jaredwray
Copy link
Owner

@PoOwAa - I should have this released in the next week or so. Will that work?

@PoOwAa
Copy link
Contributor Author

PoOwAa commented Dec 6, 2024

@PoOwAa - I should have this released in the next week or so. Will that work?

Perfect, thanks for the quick reply!

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.

2 participants