Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Mar 22, 2023
1 parent df3b20b commit a471313
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/utils/LruCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class LruCache<K, V> {
return;
}

const newItem = {
const newItem: CacheItem<K, V> = {
key,
value,
next: null,
Expand All @@ -120,7 +120,10 @@ export class LruCache<K, V> {
// Map size exceeded cache capcity. Drop tail item.
this.map.delete(this.tail.key);
this.tail = this.tail.prev;
this.tail.next = null;

if (this.tail) {
this.tail.next = null;
}
}
}

Expand Down Expand Up @@ -159,8 +162,13 @@ export class LruCache<K, V> {
if (item === this.head) return item;

this.removeItemFromList(item);
// …and put it to the front.
this.head.prev = item;

// Put item to the front.

if (this.head) {
this.head.prev = item;
}

item.prev = null;
item.next = this.head;
this.head = item;
Expand Down

0 comments on commit a471313

Please sign in to comment.