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

fix(types): introduce the MapLike-type instead of using Map #25

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

Conversation

aslushnikov
Copy link

As of today, the https://github.com/isaacs/node-lru-cache cannot be used as a cache for memoization since LRUCache doesn't define the Symbol.toStringTag.

This patch narrows down type requirements for cache implementations.

As of today, the https://github.com/isaacs/node-lru-cache cannot be used
as a cache for memoization since `LRUCache` doesn't define the
`Symbol.toStringTag`.

This patch narrows down type requirements for cache implementations.
@aslushnikov aslushnikov requested a review from a team as a code owner November 30, 2023 03:05
@peterbe
Copy link
Contributor

peterbe commented Aug 9, 2024

import memoize from "@github/memoize";

import { LRUCache } from "lru-cache";

// const myCache = new Map<string, string>();
const myCache = new LRUCache<string, string>({ max: 2 });

const randomName = memoize(
  function randomName(length: number) {
    const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const lower = "abcdefghijklmnopqrstuvwxyz";
    let result = "";
    for (let i = 0; i < length; i++) {
      result += (i === 0 ? upper : lower).charAt(
        Math.floor(Math.random() * upper.length)
      );
    }
    return result;
  },
  { cache: myCache }
);

function main() {
  console.log("hello", randomName(5));
  console.log("Hullo", randomName(5));
  console.log("Heil", randomName(5));

  console.log(myCache);
}

main();

works.

Was it perhaps not working in late 2023?

@@ -1,3 +1,10 @@
type MapLike<K, V> = {
Copy link

Choose a reason for hiding this comment

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

👋🏾 from Web Systems - bumping this comment #25 (comment)

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.

3 participants