mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Add getOwn utility function
This commit is contained in:
13
ts/util/getOwn.ts
Normal file
13
ts/util/getOwn.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user