bito-code-review[bot] commented on code in PR #39535:
URL: https://github.com/apache/superset/pull/39535#discussion_r3329278266
##########
superset-frontend/packages/superset-ui-core/src/utils/lruCache.ts:
##########
@@ -55,7 +55,12 @@ class LRUCache<T> {
throw new TypeError('The LRUCache key must be string.');
}
if (this.cache.size >= this.capacity) {
- this.cache.delete(this.cache.keys().next().value);
+ // Forward-compat: TS 6.0 types IteratorResult.value as `string |
undefined`
+ // when not explicitly checked; guard before passing to Map#delete.
+ const oldestKey = this.cache.keys().next().value;
+ if (oldestKey !== undefined) {
+ this.cache.delete(oldestKey);
+ }
Review Comment:
<!-- Bito Reply -->
The discussion in the thread revolves around whether the `if (oldestKey !==
undefined)` guard should be removed from the `LRUCache` implementation. The
reviewer insists that the guard is necessary for TypeScript 6.0
forward-compatibility, as `Map.keys().next().value` is typed as `K |
undefined`, and the guard ensures type safety under strict null checks. Bito's
suggestions to remove the guard are declined because they would violate
TypeScript's type-checking rules, even if the runtime logic seems safe. The
thread is closed with the conclusion that the guard must remain for type
correctness.
**superset-frontend/packages/superset-ui-core/src/utils/lruCache.ts**
```
this.cache.delete(this.cache.keys().next().value);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]