From a4713137cf21893cf5737245bd6f8d416367507e Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 22 Mar 2023 15:51:28 +0100 Subject: [PATCH] Fix type issues --- src/utils/LruCache.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils/LruCache.ts b/src/utils/LruCache.ts index 39f84e3fa6b2..8fe577e6767b 100644 --- a/src/utils/LruCache.ts +++ b/src/utils/LruCache.ts @@ -93,7 +93,7 @@ export class LruCache { return; } - const newItem = { + const newItem: CacheItem = { key, value, next: null, @@ -120,7 +120,10 @@ export class LruCache { // 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; + } } } @@ -159,8 +162,13 @@ export class LruCache { 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;