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

Request cache: Fix type error when deleting possibly undefined oldest entry #246

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

tharropoulos
Copy link
Contributor

Change Summary

Fixes a tsc error about oldestEntry potentially being undefined:

    const isCacheOverMaxSize = this.responseCache.size > maxSize;
    if (isCacheOverMaxSize) {
      const oldestEntry = this.responseCache.keys().next().value; // ❌ Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

      this.responseCache.delete(oldestEntry);
    }

to just checking if it is defined, otherwise it just moves on:

      const oldestEntry = this.responseCache.keys().next().value;
      if (oldestEntry) {
        this.responseCache.delete(oldestEntry);
      }

This change tries to address the type error while not introducing any regressions by changing the underlying logic by throwing or returning early.

PR Checklist

@jasonbosco jasonbosco merged commit 72f0c90 into typesense:master Nov 18, 2024
1 check passed
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