Strict types in RemoteConfig

This commit is contained in:
Fedor Indutny 2023-11-02 19:14:38 +01:00 committed by GitHub
parent a3065796fe
commit 86e6c2499c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 =