signal-desktop/ts/util/getOwn.ts
2020-11-04 11:56:49 -08:00

13 lines
423 B
TypeScript

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { has } from 'lodash';
// We want this to work with any object, so we allow `object` here.
// eslint-disable-next-line @typescript-eslint/ban-types
export function getOwn<TObject extends object, TKey extends keyof TObject>(
obj: TObject,
key: TKey
): TObject[TKey] | undefined {
return has(obj, key) ? obj[key] : undefined;
}