Update typescript to 4.8.4

This commit is contained in:
Fedor Indutny 2022-11-14 11:35:37 -08:00 committed by GitHub
parent 4c622b6f81
commit e6ebfe4fca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 133 additions and 167 deletions

View file

@ -1,17 +1,15 @@
// Copyright 2019-2021 Signal Messenger, LLC
// Copyright 2019-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function makeLookup<T>(
items: ReadonlyArray<T>,
key: keyof T
): Record<string, T> {
return (items || []).reduce((lookup, item) => {
if (item !== undefined && item[key] !== undefined) {
// The force cast is necessary if we want the keyof T above, and the flexibility
// to pass anything in. And of course we're modifying a parameter!
// eslint-disable-next-line no-param-reassign
lookup[String(item[key])] = item;
const result: Record<string, T> = {};
for (const item of items) {
if (item != null && item[key] !== undefined) {
result[String(item[key])] = item;
}
return lookup;
}, {} as Record<string, T>);
}
return result;
}