Improve types for lru-cache v7#59162
Conversation
|
@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 PRCode ReviewsBecause 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
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"
} |
|
🔔 @Bartvds @BendingBender — please review this PR in the next few days. Be sure to explicitly select |
types/lru-cache/lru-cache-tests.ts
Outdated
| }, | ||
| }); | ||
| new LRUCache<string, Foo>({ max: num }); // $ExpectType LRUCache<string, Foo> | ||
| new LRUCache<string, Foo>(); // $ExpectType LRUCache<string, Foo> |
There was a problem hiding this comment.
Initializing the cache without options in the constructor is no longer possible since v7
|
@dhensby You did the last major rewrite of types for |
dhensby
left a comment
There was a problem hiding this comment.
👍 looks great from my point of view. Thanks for catching some issues and the jsdoc improvements!
|
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? |
|
@dhensby The idea for that PR was to move TS definition into the actual package for |
|
The comment I was talking about was this one:
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 |
|
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. |
|
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! |
isaacs
left a comment
There was a problem hiding this comment.
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; | ||
|
|
There was a problem hiding this comment.
| /** | |
| * 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>;There was a problem hiding this comment.
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;
}|
So, yes, v7.7.0 will update the |
|
@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! |
…ibility in return types, and mark constructor options as not optional
|
@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. |
… is required by the constructor @see https://github.com/isaacs/node-lru-cache#storage-bounds-safety
|
@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! |
|
@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:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ (@Bartvds, @BendingBender: you can do this too.) |
|
Ready to merge |
Please fill in this template.
npm test <package to test>.If changing an existing definition: