From 87f93d77198e320cb07379f68f104a311d3de350 Mon Sep 17 00:00:00 2001 From: yougotwill Date: Thu, 6 Feb 2025 09:25:56 +1100 Subject: [PATCH] feat: add typings for feature flags --- ts/types/Util.ts | 11 +++++++++++ ts/window.d.ts | 36 ++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/ts/types/Util.ts b/ts/types/Util.ts index fea003134..d14f410f5 100644 --- a/ts/types/Util.ts +++ b/ts/types/Util.ts @@ -5,3 +5,14 @@ export type RenderTextCallbackType = (options: { }) => JSX.Element; export type LocalizerType = typeof window.i18n; + +/** + * Recursively get all keys of an object, including nested objects treating them as strings + */ +export type RecursiveKeys = T extends object + ? { + [K in Extract]: + | K + | (T[K] extends object ? `${K}.${RecursiveKeys}` : never); + }[Extract] + : never; diff --git a/ts/window.d.ts b/ts/window.d.ts index cb91d9317..7c1278cb8 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -13,6 +13,25 @@ export interface LibTextsecure { messaging: boolean; } +export type SessionFeatureFlags = { + useOnionRequests: boolean; + useTestNet: boolean; + useClosedGroupV2: boolean; + useClosedGroupV2QAButtons: boolean; + forceLegacyGroupsDeprecated: boolean; + replaceLocalizedStringsWithKeys: boolean; + debug: { + debugLogging: boolean; + debugLibsessionDumps: boolean; + debugBuiltSnodeRequests: boolean; + debugFileServerRequests: boolean; + debugNonSnodeRequests: boolean; + debugOnionRequests: boolean; + }; +}; + +export type SessionFeatureFlagsKeys = RecursiveKeys; + /* We declare window stuff here instead of global.d.ts because we are importing other declarations. If you import anything in global.d.ts, the type system won't work correctly. @@ -98,22 +117,7 @@ declare global { inEnglish: I18nMethods['inEnglish']; }; log: any; - sessionFeatureFlags: { - useOnionRequests: boolean; - useTestNet: boolean; - useClosedGroupV2: boolean; - useClosedGroupV2QAButtons: boolean; - forceLegacyGroupsDeprecated: boolean; - replaceLocalizedStringsWithKeys: boolean; - debug: { - debugLogging: boolean; - debugLibsessionDumps: boolean; - debugBuiltSnodeRequests: boolean; - debugFileServerRequests: boolean; - debugNonSnodeRequests: boolean; - debugOnionRequests: boolean; - }; - }; + sessionFeatureFlags: SessionFeatureFlags; onLogin: (pw: string) => Promise; // only set on the password window onTryPassword: (pw: string) => Promise; // only set on the main window persistStore?: Persistor;