From 82e0eb1894eb027de74eaf715ea85febeaff6dce Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 1/9] Adding NumberTypeAnnotation to Codegen Schema (#54586) Summary: Adding NumberTypeAnnotation to the Codegen Schema in order to obtain parity with String & Boolean which will be the Union types Changelog: [Internal] Differential Revision: D87374063 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 4 ++++ packages/react-native-codegen/src/CodegenSchema.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index 2d28bbfe7e271c..4f1ad89b87e107 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -26,6 +26,10 @@ export interface FloatTypeAnnotation { readonly type: 'FloatTypeAnnotation'; } +export interface NumberTypeAnnotation { + readonly type: 'NumberTypeAnnotation'; +} + export interface BooleanTypeAnnotation { readonly type: 'BooleanTypeAnnotation'; } diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 99299dafc3c043..c5e154c5b7d84e 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -30,6 +30,10 @@ export type FloatTypeAnnotation = $ReadOnly<{ type: 'FloatTypeAnnotation', }>; +export type NumberTypeAnnotation = $ReadOnly<{ + type: 'NumberTypeAnnotation', +}>; + export type BooleanTypeAnnotation = $ReadOnly<{ type: 'BooleanTypeAnnotation', }>; From 976991215af0f16bf004d0da72152ff2078d9e32 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 2/9] Introduce generic UnionTypeAnnotation (#54587) Summary: Adding the generic type T UnionTypeAnnotation. This will be used later to create Unions of types String, Number & Boolean. Changelog: [Internal] Differential Revision: D87374445 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 5 +++++ packages/react-native-codegen/src/CodegenSchema.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index 4f1ad89b87e107..fc68a17224480b 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -53,6 +53,11 @@ export interface ObjectTypeAnnotation { readonly baseTypes?: readonly string[] | undefined; } +export interface UnionTypeAnnotation { + readonly type: 'UnionTypeAnnotation'; + readonly types: readonly T[]; +} + export interface MixedTypeAnnotation { readonly type: 'MixedTypeAnnotation'; } diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index c5e154c5b7d84e..98cf7af93960ab 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -72,6 +72,11 @@ export type ObjectTypeAnnotation<+T> = $ReadOnly<{ baseTypes?: $ReadOnlyArray, }>; +export type UnionTypeAnnotation<+T> = $ReadOnly<{ + type: 'UnionTypeAnnotation', + types: $ReadOnlyArray, +}>; + export type MixedTypeAnnotation = $ReadOnly<{ type: 'MixedTypeAnnotation', }>; From c1574fc305ba30a717e2c0370ecdb274322a8ffe Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 3/9] Introduce NumberLiteralType & StringLiteralType in TS (#54588) Summary: Introduce NumberLiteralType & StringLiteralType in TypeScript just as they already exist in Flow here: https://www.internalfb.com/code/fbsource/[9b248afa0cd5548b81dd44f1042b230e6069432b]/xplat/js/react-native-github/packages/react-native-codegen/src/CodegenSchema.js?lines=41-53 Changelog: [Internal] Differential Revision: D87375511 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index fc68a17224480b..24f82ad80b0c40 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -46,6 +46,16 @@ export interface VoidTypeAnnotation { readonly type: 'VoidTypeAnnotation'; } +export interface NumberLiteralTypeAnnotation { + readonly type: 'NumberLiteralTypeAnnotation'; + readonly value: number; +} + +export interface StringLiteralTypeAnnotation { + readonly type: 'StringLiteralTypeAnnotation'; + readonly value: string; +} + export interface ObjectTypeAnnotation { readonly type: 'ObjectTypeAnnotation'; readonly properties: readonly NamedShape[]; From aa47f0c7a1f5a3e83a079fa5bc69aef9484c15c9 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 4/9] Introduce TupleTypeAnnotation Summary: TupleTypeAnnotation is added for parity with UnionTypeAnnotation to support future implementation. Currently limited to String and Number literals as per: https://docs.google.com/document/d/1pTBMOEIov5n5-0L9z925XPvGX1YxlmI6n6FJvd0oXtE/edit?tab=t.0#heading=h.fhe5py9plytd Differential Revision: D87383455 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 7 +++++++ packages/react-native-codegen/src/CodegenSchema.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index 24f82ad80b0c40..a220ca10fa3e43 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -68,6 +68,13 @@ export interface UnionTypeAnnotation { readonly types: readonly T[]; } +// TODO(T72031674): TupleTypeAnnotation is added for parity with UnionTypeAnnotation +// to support future implementation. Currently limited to String and Number literals. +export interface TupleTypeAnnotation { + readonly type: 'TupleTypeAnnotation'; + readonly types: StringLiteralTypeAnnotation | NumberLiteralTypeAnnotation; +} + export interface MixedTypeAnnotation { readonly type: 'MixedTypeAnnotation'; } diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 98cf7af93960ab..44286533e2a59a 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -77,6 +77,13 @@ export type UnionTypeAnnotation<+T> = $ReadOnly<{ types: $ReadOnlyArray, }>; +// TODO(T72031674): TupleTypeAnnotation is added for parity with UnionTypeAnnotation +// to support future implementation. Currently limited to String and Number literals. +export type TupleTypeAnnotation = $ReadOnly<{ + type: 'TupleTypeAnnotation', + types: StringLiteralTypeAnnotation | NumberLiteralTypeAnnotation, +}>; + export type MixedTypeAnnotation = $ReadOnly<{ type: 'MixedTypeAnnotation', }>; From f42559132b7ef609690c457163cdc92b503abb55 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 5/9] Introduce BooleanLiteralTypeAnnotation (#54590) Summary: Introduce `BooleanLiteralTypeAnnotation` in Flow & TypeScript to match the existing `StringLiteralTypeAnnotation` & `NumberLiteralTypeAnnotation` since Unions will be supporting Booleans along with String & Number Changelog: [Internal] Differential Revision: D87384473 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 5 +++++ packages/react-native-codegen/src/CodegenSchema.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index a220ca10fa3e43..88061b89dc6f4e 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -56,6 +56,11 @@ export interface StringLiteralTypeAnnotation { readonly value: string; } +export interface BooleanLiteralTypeAnnotation { + readonly type: 'BooleanLiteralTypeAnnotation'; + readonly value: boolean; +} + export interface ObjectTypeAnnotation { readonly type: 'ObjectTypeAnnotation'; readonly properties: readonly NamedShape[]; diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 44286533e2a59a..2684864829d6a5 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -56,6 +56,11 @@ export type StringLiteralTypeAnnotation = $ReadOnly<{ value: string, }>; +export type BooleanLiteralTypeAnnotation = $ReadOnly<{ + type: 'BooleanLiteralTypeAnnotation', + value: boolean, +}>; + export type StringLiteralUnionTypeAnnotation = $ReadOnly<{ type: 'StringLiteralUnionTypeAnnotation', types: $ReadOnlyArray, From a3429bee0ddbc6f200199e298e69ab08e19e20cc Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 6/9] Introduce the supported member types of Union (#54591) Summary: Following types will be supported in Union currently: 1. Number : NumberType + NumberLiteralType 2. Boolean : BooleanType + BooleanLiteralType 3. String : StringType + StringLiteralType 4. Object: NativeModuleObjectType These are the only ones that exist today as per : https://docs.google.com/document/d/1pTBMOEIov5n5-0L9z925XPvGX1YxlmI6n6FJvd0oXtE/edit?tab=t.0#heading=h.fhe5py9plytd Changelog: [Internal] Differential Revision: D87384995 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 9 +++++++++ packages/react-native-codegen/src/CodegenSchema.js | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index 88061b89dc6f4e..4f08147cffa278 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -405,6 +405,15 @@ export type UnionTypeAnnotationMemberType = | 'ObjectTypeAnnotation' | 'StringTypeAnnotation'; +export type NativeModuleUnionTypeAnnotationMemberType = + | NativeModuleObjectTypeAnnotation + | StringLiteralTypeAnnotation + | NumberLiteralTypeAnnotation + | BooleanLiteralTypeAnnotation + | BooleanTypeAnnotation + | StringTypeAnnotation + | NumberTypeAnnotation; + export interface NativeModuleUnionTypeAnnotation { readonly type: 'UnionTypeAnnotation'; readonly memberType: UnionTypeAnnotationMemberType; diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 2684864829d6a5..a40c239390851d 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -384,6 +384,15 @@ export type UnionTypeAnnotationMemberType = | 'ObjectTypeAnnotation' | 'StringTypeAnnotation'; +export type NativeModuleUnionTypeAnnotationMemberType = + | NativeModuleObjectTypeAnnotation + | StringLiteralTypeAnnotation + | NumberLiteralTypeAnnotation + | BooleanLiteralTypeAnnotation + | BooleanTypeAnnotation + | StringTypeAnnotation + | NumberTypeAnnotation; + export type NativeModuleUnionTypeAnnotation = $ReadOnly<{ type: 'UnionTypeAnnotation', memberType: UnionTypeAnnotationMemberType, From fa5c71afa7e26479f5545acbc3ccffef36dad958 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 7/9] Introduce UnionTypeAnnotation for Number & Boolean (#54592) Summary: Adding `NumberLiteralUnionTypeAnnotation` & `BooleanLiteralUnionTypeAnnotation` to Flow & TypeScript so that they are in parity with other Union type : `StringLiteralUnionTypeAnnotation`. Number & Boolean aren't used anywhere yet. Changelog: [Internal] Differential Revision: D87386144 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 6 ++++++ packages/react-native-codegen/src/CodegenSchema.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index 4f08147cffa278..d5ab6ef8669078 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -340,6 +340,12 @@ export interface StringLiteralUnionTypeAnnotation { readonly types: NativeModuleStringLiteralTypeAnnotation[]; } +export type NumberLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + +export type BooleanLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + export interface NativeModuleNumberTypeAnnotation { readonly type: 'NumberTypeAnnotation'; } diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index a40c239390851d..bc8f9cdcb78047 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -66,6 +66,12 @@ export type StringLiteralUnionTypeAnnotation = $ReadOnly<{ types: $ReadOnlyArray, }>; +export type NumberLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + +export type BooleanLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + export type VoidTypeAnnotation = $ReadOnly<{ type: 'VoidTypeAnnotation', }>; From 803b143dbc6d8d113c24fbc17a8ed7aab83152ce Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 8/9] Add BooleanLiteralTypeAnnotation to the NativeModuleBaseTypeAnnotation in Flow (#54593) Summary: Just as `NumberLiteralTypeAnnotation` was part of the `NativeModuleBaseTypeAnnotation` in Flow, adding the `BooleanLiteralTypeAnnotation`. Similarly adding it to the StructCollector since this is needed for Flow exhaustiveness check in generators/modules in D87410022 NOTE: Didn't add this change for TS as both `NumberLiteralTypeAnnotation` was not included as part of `NativeModuleBaseTypeAnnotation` in TS, also the generators were not failing in TS for this. Changelog: [Internal] Differential Revision: D87392274 --- packages/react-native-codegen/src/CodegenSchema.js | 1 + .../generators/modules/GenerateModuleObjCpp/StructCollector.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index bc8f9cdcb78047..6a760cdd70d208 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -432,6 +432,7 @@ export type NativeModuleBaseTypeAnnotation = | StringLiteralUnionTypeAnnotation | NativeModuleNumberTypeAnnotation | NumberLiteralTypeAnnotation + | BooleanLiteralTypeAnnotation | Int32TypeAnnotation | DoubleTypeAnnotation | FloatTypeAnnotation diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js index db243d9f3024a2..88ef558f40e0bc 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js @@ -11,6 +11,7 @@ 'use strict'; import type { + BooleanLiteralTypeAnnotation, BooleanTypeAnnotation, DoubleTypeAnnotation, FloatTypeAnnotation, @@ -65,6 +66,7 @@ export type StructTypeAnnotation = | StringLiteralUnionTypeAnnotation | NativeModuleNumberTypeAnnotation | NumberLiteralTypeAnnotation + | BooleanLiteralTypeAnnotation | Int32TypeAnnotation | DoubleTypeAnnotation | FloatTypeAnnotation From 43f9687e9ab797c3ac18d62ff43ea36afdb42789 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:07:44 -0800 Subject: [PATCH 9/9] Refactor NativeModuleUnionTypeAnnotation Summary: Refactoring `NativeModuleUnionTypeAnnotation` to use the newly introduced `NativeModuleUnionTypeAnnotationMemberType` Changelog: [Internal] Differential Revision: D87386775 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 11 ++--------- packages/react-native-codegen/src/CodegenSchema.js | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index d5ab6ef8669078..a1532bb7564a2b 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -406,11 +406,6 @@ export interface NativeModulePromiseTypeAnnotation { readonly elementType: Nullable | VoidTypeAnnotation; } -export type UnionTypeAnnotationMemberType = - | 'NumberTypeAnnotation' - | 'ObjectTypeAnnotation' - | 'StringTypeAnnotation'; - export type NativeModuleUnionTypeAnnotationMemberType = | NativeModuleObjectTypeAnnotation | StringLiteralTypeAnnotation @@ -420,10 +415,8 @@ export type NativeModuleUnionTypeAnnotationMemberType = | StringTypeAnnotation | NumberTypeAnnotation; -export interface NativeModuleUnionTypeAnnotation { - readonly type: 'UnionTypeAnnotation'; - readonly memberType: UnionTypeAnnotationMemberType; -} +export type NativeModuleUnionTypeAnnotation = + UnionTypeAnnotation; export interface NativeModuleMixedTypeAnnotation { readonly type: 'MixedTypeAnnotation'; diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 6a760cdd70d208..2d63fff6cc8013 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -385,11 +385,6 @@ export type NativeModulePromiseTypeAnnotation = $ReadOnly<{ elementType: VoidTypeAnnotation | Nullable, }>; -export type UnionTypeAnnotationMemberType = - | 'NumberTypeAnnotation' - | 'ObjectTypeAnnotation' - | 'StringTypeAnnotation'; - export type NativeModuleUnionTypeAnnotationMemberType = | NativeModuleObjectTypeAnnotation | StringLiteralTypeAnnotation @@ -399,10 +394,8 @@ export type NativeModuleUnionTypeAnnotationMemberType = | StringTypeAnnotation | NumberTypeAnnotation; -export type NativeModuleUnionTypeAnnotation = $ReadOnly<{ - type: 'UnionTypeAnnotation', - memberType: UnionTypeAnnotationMemberType, -}>; +export type NativeModuleUnionTypeAnnotation = + UnionTypeAnnotation; export type NativeModuleMixedTypeAnnotation = $ReadOnly<{ type: 'MixedTypeAnnotation',