Add getOwn
utility function
This commit is contained in:
parent
d1c63609a7
commit
ca83281986
3 changed files with 66 additions and 10 deletions
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue