// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only export type NullToUndefined = Extract extends never ? T : Exclude | undefined; export function dropNull( value: NonNullable | null | undefined ): T | undefined { // eslint-disable-next-line eqeqeq if (value === null) { return undefined; } return value; } // eslint-disable-next-line @typescript-eslint/no-explicit-any export function shallowDropNull( value: O | null | undefined ): | { [Property in keyof O]: NullToUndefined; } | undefined { if (value == null) { return undefined; } // eslint-disable-next-line @typescript-eslint/no-explicit-any const result: any = {}; for (const [key, propertyValue] of Object.entries(value)) { result[key] = dropNull(propertyValue); } return result; }