From 66ffa5ee4d672b492fcf1ced9013e27f248b210f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 29 Oct 2024 08:02:54 -0700 Subject: [PATCH] Small improvement in types for feature flags definitions in JS (#47239) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47239 Changelog: [internal] Small refactor of the types for feature flags in JS to make objects read-only. Reviewed By: mdvacca Differential Revision: D65058612 fbshipit-source-id: 0d72df2f4afebf0426b9ac76a8f8b195c74fea52 --- .../scripts/featureflags/types.js | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/react-native/scripts/featureflags/types.js b/packages/react-native/scripts/featureflags/types.js index 1e328087159..9316c9487f4 100644 --- a/packages/react-native/scripts/featureflags/types.js +++ b/packages/react-native/scripts/featureflags/types.js @@ -10,30 +10,30 @@ export type FeatureFlagValue = boolean | number | string; -export type FeatureFlagDefinitions = { +export type FeatureFlagDefinitions = $ReadOnly<{ common: CommonFeatureFlagList, jsOnly: JsOnlyFeatureFlagList, -}; +}>; -type CommonFeatureFlagList = { - [flagName: string]: { +export type CommonFeatureFlagList = $ReadOnly<{ + [flagName: string]: $ReadOnly<{ defaultValue: FeatureFlagValue, metadata: FeatureFlagMetadata, // Indicates if this API should only be defined in JavaScript, only to // preserve backwards compatibility with existing native code temporarily. skipNativeAPI?: true, - }, -}; + }>, +}>; -type JsOnlyFeatureFlagList = { - [flagName: string]: { +export type JsOnlyFeatureFlagList = $ReadOnly<{ + [flagName: string]: $ReadOnly<{ defaultValue: FeatureFlagValue, metadata: FeatureFlagMetadata, - }, -}; + }>, +}>; -type FeatureFlagMetadata = - | { +export type FeatureFlagMetadata = + | $ReadOnly<{ purpose: 'experimentation', /** * Aproximate date when the flag was added. @@ -41,25 +41,25 @@ type FeatureFlagMetadata = */ dateAdded: string, description: string, - } - | { + }> + | $ReadOnly<{ purpose: 'operational' | 'release', description: string, - }; + }>; -export type GeneratorConfig = { +export type GeneratorConfig = $ReadOnly<{ featureFlagDefinitions: FeatureFlagDefinitions, jsPath: string, commonCxxPath: string, commonNativeModuleCxxPath: string, androidPath: string, androidJniPath: string, -}; +}>; -export type GeneratorOptions = { +export type GeneratorOptions = $ReadOnly<{ verifyUnchanged: boolean, -}; +}>; -export type GeneratorResult = { +export type GeneratorResult = $ReadOnly<{ [path: string]: string /* content */, -}; +}>;