More protobufjs migration

This commit is contained in:
Fedor Indutny 2021-07-09 12:36:10 -07:00 committed by GitHub
parent cf06e6638e
commit ddbbe3a6b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 3967 additions and 3369 deletions

View file

@ -1,5 +1,10 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* eslint-disable no-restricted-syntax */
export type NullToUndefined<T> = Extract<T, null> extends never
? T
: Exclude<T, null> | undefined;
export function dropNull<T>(
value: NonNullable<T> | null | undefined
@ -9,3 +14,25 @@ export function dropNull<T>(
}
return value;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function shallowDropNull<O extends { [key: string]: any }>(
value: O | null | undefined
):
| {
[Property in keyof O]: NullToUndefined<O[Property]>;
}
| undefined {
if (value === null || value === undefined) {
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;
}