refactor(assert): remove unnecessary getValFromKeyedCollection() (#5921)

* refactor(assert): remove unnecessary getValFromKeyedCollection function

* Use type assertion instead of narrowing w unreachable path
This commit is contained in:
lionel-rowe 2024-09-09 12:11:27 +08:00 committed by GitHub
parent 2fe19de48f
commit 23b4d2a034
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,15 +2,10 @@
// This module is browser compatible.
type KeyedCollection = Set<unknown> | Map<unknown, unknown>;
function isKeyedCollection(x: unknown): x is KeyedCollection {
return x instanceof Set || x instanceof Map;
}
function getValFromKeyedCollection(kc: KeyedCollection, key: unknown) {
return kc instanceof Map ? kc.get(key) : key;
}
function constructorsEqual(a: object, b: object) {
return a.constructor === b.constructor ||
a.constructor === Object && !b.constructor ||
@ -106,10 +101,7 @@ export function equal(c: unknown, d: unknown): boolean {
for (const key of aKeys) {
if (
!b.has(key) ||
!compare(
getValFromKeyedCollection(a, key),
getValFromKeyedCollection(b, key),
)
!compare(a.get(key), (b as Map<unknown, unknown>).get(key))
) {
return false;
}