From 86e6c2499cacaffdc103f20d9ffbabcce3434f29 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 2 Nov 2023 19:14:38 +0100 Subject: [PATCH] Strict types in RemoteConfig --- ts/RemoteConfig.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ts/RemoteConfig.ts b/ts/RemoteConfig.ts index e7833a92b251..b531948e6c42 100644 --- a/ts/RemoteConfig.ts +++ b/ts/RemoteConfig.ts @@ -10,6 +10,7 @@ import { parseIntOrThrow } from './util/parseIntOrThrow'; import { SECOND, HOUR } from './util/durations'; import * as Bytes from './Bytes'; import { uuidToBytes } from './util/uuidToBytes'; +import { dropNull } from './util/dropNull'; import { HashType } from './types/Crypto'; import { getCountryCode } from './types/PhoneNumber'; @@ -54,7 +55,7 @@ type ConfigValueType = { name: ConfigKeyType; enabled: boolean; enabledAt?: number; - value?: unknown; + value?: string; }; export type ConfigMapType = { [key in ConfigKeyType]?: ConfigValueType; @@ -105,7 +106,11 @@ export const refreshRemoteConfig = async ( const oldConfig = config; config = newConfig.reduce((acc, { name, enabled, value }) => { const previouslyEnabled: boolean = get(oldConfig, [name, 'enabled'], false); - const previousValue: unknown = get(oldConfig, [name, 'value'], undefined); + const previousValue: string | undefined = get( + oldConfig, + [name, 'value'], + undefined + ); // If a flag was previously not enabled and is now enabled, // record the time it was enabled const enabledAt: number | undefined = @@ -115,7 +120,7 @@ export const refreshRemoteConfig = async ( name: name as ConfigKeyType, enabled, enabledAt, - value, + value: dropNull(value), }; const hasChanged =