Skip to content

Improve types for lru-cache v7#59162

Merged
typescript-bot merged 5 commits intoDefinitelyTyped:masterfrom
eugene1g:master
Mar 25, 2022
Merged

Improve types for lru-cache v7#59162
typescript-bot merged 5 commits intoDefinitelyTyped:masterfrom
eugene1g:master

Conversation

@eugene1g
Copy link
Copy Markdown
Contributor

@eugene1g eugene1g commented Mar 6, 2022

Please fill in this template.

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the header.

@eugene1g eugene1g requested a review from Bartvds as a code owner March 6, 2022 14:49
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Mar 6, 2022

@eugene1g Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by a DT maintainer

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 59162,
  "author": "eugene1g",
  "headCommitOid": "0ac516dc69b67f03ead065894d83a1d84b8eb66f",
  "mergeBaseOid": "79b8e7e92c21e9b64569caf4ed82adbdf0605026",
  "lastPushDate": "2022-03-25T13:15:05.000Z",
  "lastActivityDate": "2022-03-25T23:03:28.000Z",
  "mergeOfferDate": "2022-03-25T22:36:35.000Z",
  "mergeRequestDate": "2022-03-25T23:03:24.000Z",
  "mergeRequestUser": "eugene1g",
  "hasMergeConflict": false,
  "isFirstContribution": true,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "lru-cache",
      "kind": "edit",
      "files": [
        {
          "path": "types/lru-cache/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/lru-cache/lru-cache-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "Bartvds",
        "BendingBender"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "amcasey",
      "date": "2022-03-25T22:35:57.000Z",
      "isMaintainer": true
    },
    {
      "type": "stale",
      "reviewer": "isaacs",
      "date": "2022-03-17T16:50:41.000Z",
      "abbrOid": "612ac2b"
    },
    {
      "type": "stale",
      "reviewer": "dhensby",
      "date": "2022-03-06T15:16:22.000Z",
      "abbrOid": "612ac2b"
    }
  ],
  "mainBotCommentID": 1059976288,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Check Config Changes a module config files labels Mar 6, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @Bartvds @BendingBender — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

},
});
new LRUCache<string, Foo>({ max: num }); // $ExpectType LRUCache<string, Foo>
new LRUCache<string, Foo>(); // $ExpectType LRUCache<string, Foo>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Initializing the cache without options in the constructor is no longer possible since v7

@eugene1g
Copy link
Copy Markdown
Contributor Author

eugene1g commented Mar 6, 2022

@dhensby You did the last major rewrite of types for lru-cache to get it to v7 (thanks!) - would you please glance over these tweaks?

Copy link
Copy Markdown
Contributor

@dhensby dhensby left a comment

Choose a reason for hiding this comment

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

👍 looks great from my point of view. Thanks for catching some issues and the jsdoc improvements!

@typescript-bot typescript-bot added the Other Approved This PR was reviewed and signed-off by a community member. label Mar 6, 2022
@dhensby
Copy link
Copy Markdown
Contributor

dhensby commented Mar 17, 2022

In isaacs/node-lru-cache#201, @isaacs indicated he would be happy to review your changes, would it be worth adding them as a definition owner for this project?

@eugene1g
Copy link
Copy Markdown
Contributor Author

@dhensby The idea for that PR was to move TS definition into the actual package for lru-cache, however the lib author mentioned that they do not wish to take on the responsibility for TS types (see the comment isaacs/node-lru-cache#201 (comment)), so I don't think we should add them as the owner here as it would set implicit expectations that they are maintaining these types.

@dhensby
Copy link
Copy Markdown
Contributor

dhensby commented Mar 17, 2022

The comment I was talking about was this one:

I'm definitely down to review and help make [the typings] as accurate as possible, I just can't sign up for ongoing maintenance [of the types] without tests

As the "owner", the expectations are really there to review other's contributions to the types and not to actually place any obligation to actively keep the types up to date.

I guess I'd just like someone knowledgeable and active to be able to review the community submitted typings

@isaacs
Copy link
Copy Markdown

isaacs commented Mar 17, 2022

I'm happy to review this or any oss where I might provide value, time allowing, when requested. I'll take a look at this today. I just need it to not be in a repo I own if I'm not actively maintaining it.

@typescript-bot
Copy link
Copy Markdown
Contributor

Re-ping @Bartvds, @BendingBender:

This PR has been out for over a week, yet I haven't seen any reviews.

Could someone please give it some attention? Thanks!

@typescript-bot typescript-bot added the Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. label Mar 17, 2022
Copy link
Copy Markdown

@isaacs isaacs left a comment

Choose a reason for hiding this comment

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

As of 7.6.0, options.max is actually not required. However, at least one of ttl, maxSize, and max are required. See isaacs/node-lru-cache@c29079d

I'm not sure the best way to express this in TypeScript, but that's how it works 😅

public readonly ttlAutopurge: boolean;
public readonly allowStale: boolean;
public readonly updateAgeOnGet: boolean;

Copy link
Copy Markdown

@isaacs isaacs Mar 17, 2022

Choose a reason for hiding this comment

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

Suggested change
/**
* since: 7.6.0
*/
public readonly fetchMethod: LRUCache.Fetcher<K, V> | null;

Then later on somewhere, I think this would define it:

    type Fetcher<K, V> = (key: K, staleKey: K | undefined) => Promise<V>;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note also that this signature may change, as the feature is still brand new. Discussion: isaacs/node-lru-cache#216

Most likely going to land on something like:

    type Fetcher<K, V> = (key: K, staleKey: K | undefined, options: FetcherOptions) => Promise<V>;
    interface FetcherOptions {
        signal: AbortSignal;
        setOptions: LRUCache.SetOptions;
    }

@isaacs
Copy link
Copy Markdown

isaacs commented Mar 17, 2022

So, yes, v7.7.0 will update the fetchMethod() signature to fetchMethod<K, V>(key: K, oldValue: V | undefined, { signal: AbortSignal, options: { ...GetOptions, ...SetOptions } }) => Promise<V>, and the fetch() method signature becomes fetch<K, V>(key: K, fetchOptions: { ...GetOptions, ...SetOptions }) => Promise<V | undefined>

@typescript-bot typescript-bot added Has Merge Conflict This PR can't be merged because it has a merge conflict. The author needs to update it. and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Mar 17, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@eugene1g Unfortunately, this pull request currently has a merge conflict 😥. Please update your PR branch to be up-to-date with respect to master. Have a nice day!

@typescript-bot typescript-bot added Critical package and removed Has Merge Conflict This PR can't be merged because it has a merge conflict. The author needs to update it. labels Mar 18, 2022
@typescript-bot typescript-bot removed Other Approved This PR was reviewed and signed-off by a community member. Popular package This PR affects a popular package (as counted by NPM download counts). labels Mar 18, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@isaacs, @dhensby Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Mar 18, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@eugene1g The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Mar 18, 2022
@eugene1g
Copy link
Copy Markdown
Contributor Author

Thanks, @isaacs. I added definitions for the new features in 7.6+7.7, and clarified the constructor definition to show that max is not strictly required, but you must provide one of max|maxSize|ttl.

IMO ready to merge. @dhensby this won't conflict with your PR at #59327

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Mar 23, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@eugene1g One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you!

@typescript-bot typescript-bot removed Revision needed This PR needs code changes before it can be merged. Check Config Changes a module config files labels Mar 25, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@amcasey, @isaacs, @dhensby Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner labels Mar 25, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@eugene1g: Everything looks good here. I am ready to merge this PR (at 0ac516d) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@Bartvds, @BendingBender: you can do this too.)

@eugene1g
Copy link
Copy Markdown
Contributor Author

Ready to merge

@eugene1g
Copy link
Copy Markdown
Contributor Author

Thanks, @amcasey @dhensby & @isaacs!

@typescript-bot typescript-bot merged commit 0db8d23 into DefinitelyTyped:master Mar 25, 2022
@eugene1g eugene1g mentioned this pull request Mar 27, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants