Skip to content

fix: generic type propagation in get, mget, and take methods#1602

Merged
jaredwray merged 2 commits intomainfrom
claude/fix-issue-1601-CJTgs
Mar 22, 2026
Merged

fix: generic type propagation in get, mget, and take methods#1602
jaredwray merged 2 commits intomainfrom
claude/fix-issue-1601-CJTgs

Conversation

@jaredwray
Copy link
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing guidelines and Code of Conduct
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

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(), and take() methods in both NodeCache and NodeCacheStore classes.

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:

  1. The class-level generic type to be used by default
  2. Methods to optionally override the type if needed
  3. Proper type inference throughout the call chain

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.ts and index.test.ts that verify:

  • Class-level generic types are properly propagated through get(), mget(), and take() methods
  • Type inference works correctly for complex types (objects with multiple properties)
  • Methods return the expected typed values
  • The take() method correctly removes keys after retrieval

All existing tests continue to pass with 100% code coverage maintained.

https://claude.ai/code/session_01AfCP11dTBM4KuAcBdJRc3j

#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
@jaredwray
Copy link
Owner Author

#1601

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 NodeCache and NodeCacheStore classes. Previously, method-level generic type parameters in get(), mget(), and take() methods inadvertently shadowed the class-level generic type, leading to incorrect type inference. The solution involves adjusting these method signatures to default to the class's generic type, thereby restoring proper type propagation and enhancing overall type safety and predictability across the library's cache operations.

Highlights

  • Generic Type Parameter Shadowing Fix: Modified get(), mget(), and take() methods in both NodeCache and NodeCacheStore classes to use a default generic type parameter <V = T> instead of <T>.
  • Improved Type Inference: This change ensures that the class-level generic type is used by default, allowing for proper type inference and providing the option to override the type at the method level if needed.
  • Comprehensive Testing: Added new test cases in store.test.ts and index.test.ts to verify correct propagation of class-level generic types and accurate type inference for various methods and complex types, maintaining 100% code coverage.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d94557a) to head (63f8668).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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
@jaredwray jaredwray changed the title Fix generic type propagation in get, mget, and take methods fix: generic type propagation in get, mget, and take methods Mar 22, 2026
@jaredwray jaredwray merged commit a2cbed6 into main Mar 22, 2026
10 checks passed
@jaredwray jaredwray deleted the claude/fix-issue-1601-CJTgs branch March 22, 2026 00:21
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