From 455f8e4842d15e214a74f19d575c9296f4f6743a Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 1/8] 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 2d28bbfe7e2..4f1ad89b87e 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 99299dafc3c..c5e154c5b7d 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 33cc00a9a9da0e689d2245323de1cd1d9d338007 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 2/8] 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 4f1ad89b87e..fc68a172244 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 c5e154c5b7d..98cf7af9396 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 267b5847414659d5a60d829d990b67f5aafdcc76 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 3/8] 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 fc68a172244..24f82ad80b0 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 770a4dc5434a2f6762c2863ac13886ad76e4abfb Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 4/8] 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 24f82ad80b0..a220ca10fa3 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 98cf7af9396..44286533e2a 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 986feffb1f9660dd380d871b651b1dd2ee69a40f Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 5/8] 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 a220ca10fa3..88061b89dc6 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 44286533e2a..2684864829d 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 e38c9b474719fcf5f696d9507d5d88df80241ff4 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 6/8] 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 88061b89dc6..4f08147cffa 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 2684864829d..a40c2393908 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 ec0b2c8729fd33992d2e83951fb514f9dd4c2bf9 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 7/8] 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 4f08147cffa..d5ab6ef8669 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 a40c2393908..bc8f9cdcb78 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 cd44bdc6f00fb94d214545b9b52d4088a9c17690 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 19 Nov 2025 00:06:35 -0800 Subject: [PATCH 8/8] 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 bc8f9cdcb78..6a760cdd70d 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 db243d9f302..88ef558f40e 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