makeLookup: Allow for key of zero

This commit is contained in:
Scott Nonnenberg 2021-01-27 14:39:45 -08:00 committed by GitHub
parent a769402c0c
commit 12c44d40a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 3 deletions

View file

@ -6,7 +6,7 @@ export function makeLookup<T>(
key: keyof T
): Record<string, T> {
return (items || []).reduce((lookup, item) => {
if (item && item[key]) {
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