fix: generic type propagation in get, mget, and take methods#1602
fix: generic type propagation in get, mget, and take methods#1602
Conversation
#1601) Method-level <T> generics on mget, take (NodeCache) and get, mget, take (NodeCacheStore) shadowed the class-level <T>, causing TypeScript to infer unknown instead of the user-specified type. Rename to <V = T> so the class type is used by default while still allowing per-call overrides. https://claude.ai/code/session_01AfCP11dTBM4KuAcBdJRc3j
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical TypeScript type safety issue within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1602 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 2473 2473
Branches 557 558 +1
=========================================
Hits 2473 2473 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request refactors the mget, take, and get methods across NodeCache and NodeCacheStore classes to enhance TypeScript generic type inference by introducing a new generic type V = T. This allows these methods to correctly propagate the class-level generic type or accept an explicit type. New test cases were added to validate this improved type propagation, though the reviewer suggested improving the robustness of these new test assertions by making them more explicit and complete, noting that current toEqual checks are redundant and property-specific checks are incomplete.
Replace redundant toEqual + incomplete property checks with explicit toBeDefined + individual property assertions for all fields. https://claude.ai/code/session_01AfCP11dTBM4KuAcBdJRc3j
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
Bug fix - Generic type handling
Description
This PR fixes a critical issue where the class-level generic type parameter was being shadowed by method-level generic type parameters in
get(),mget(), andtake()methods in bothNodeCacheandNodeCacheStoreclasses.Problem
Previously, these methods declared their own generic type parameter
<T>, which shadowed the class-level generic type<T>. This prevented TypeScript from properly inferring the class-level type when calling these methods, forcing users to manually specify types or losing type safety.Solution
Changed method signatures to use a default generic type parameter
<V = T>instead of<T>. This allows:Changes Made
NodeCacheStore.get(): Changed from<T>to<V = T>NodeCacheStore.mget(): Changed from<T>to<V = T>NodeCacheStore.take(): Changed from<T>to<V = T>NodeCache.mget(): Changed from<T>to<V = T>NodeCache.take(): Changed from<T>to<V = T>Test Plan
Added comprehensive test cases in both
store.test.tsandindex.test.tsthat verify:get(),mget(), andtake()methodstake()method correctly removes keys after retrievalAll existing tests continue to pass with 100% code coverage maintained.
https://claude.ai/code/session_01AfCP11dTBM4KuAcBdJRc3j