From 4fb7996b40e7a3fb64410640015dc15566fdc87d Mon Sep 17 00:00:00 2001 From: Eli White Date: Fri, 3 Jan 2025 23:43:09 -0800 Subject: [PATCH 1/3] [skip ci] Make CompleteType contain module and component reserved names (#48477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Over the years of copying and moving and renaming types through CodegenSchema, this type ended up in the Command params, although the Command parser doesn't allow it. I made this change to a fixture: {F1974104959} and got this error ``` FAIL xplat/js/react-native-github/packages/react-native-codegen/src/parsers/flow/components/__tests__/component-parser-test.js ● RN Codegen Flow Parser › can generate fixture COMMANDS_DEFINED_WITH_ALL_TYPES Unsupported param type for method "scrollTo", param "speed". Found UnionTypeAnnotation 127 | default: 128 | (type: empty); > 129 | throw new Error( | ^ 130 | `Unsupported param type for method "${name}", param "${paramName}". Found ${type}`, 131 | ); 132 | } ``` Also, a default value for enum an argument of a Command doesn't make sense anyways. Commands should probably have support for enums and string literal unions, but that's out of scope here. Still need to add to this vec\concat on www: https://www.internalfb.com/code/www/[ebfa58f888a6064e17879934d447f59bcc2b6951]/flib/intern/sandcastle/react_native/ota_steps/SandcastleOTACompatibilityCheckReportingStep.php?lines=62 Changelog: [internal] Differential Revision: D67806808 --- packages/react-native-codegen/src/CodegenSchema.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 14552f63f063be..6a7adb57e11bb8 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -412,6 +412,14 @@ type NativeModuleReturnOnlyTypeAnnotation = | NativeModulePromiseTypeAnnotation | VoidTypeAnnotation; +// Add the allowed component reserved types to the native module union +export type CompleteReservedTypeAnnotation = + | ReservedTypeAnnotation + | { + type: 'ReservedTypeAnnotation', + name: ReservedPropTypeAnnotation['name'], + }; + // Used by compatibility check which needs to handle all possible types // This will eventually also include the union of all view manager types export type CompleteTypeAnnotation = @@ -421,6 +429,7 @@ export type CompleteTypeAnnotation = | EventEmitterTypeAnnotation | NativeModuleEnumDeclarationWithMembers | UnsafeAnyTypeAnnotation + | CompleteReservedTypeAnnotation // Native Module event emitters and methods | ObjectTypeAnnotation< Nullable | EventEmitterTypeAnnotation, From cef0d826aacd700d4306bdf73223426f8502f648 Mon Sep 17 00:00:00 2001 From: Eli White Date: Fri, 3 Jan 2025 23:43:09 -0800 Subject: [PATCH 2/3] [skip ci] Simplify CompleteTypeAnnotation (#48473) Summary: This is such a simpler approach lol. I'll need this later for when I want to pass in arrays or objects of these types to the compat check Changelog: [internal] Differential Revision: D67806812 --- packages/react-native-codegen/src/CodegenSchema.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 6a7adb57e11bb8..e7fc38e4f3a919 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -429,8 +429,6 @@ export type CompleteTypeAnnotation = | EventEmitterTypeAnnotation | NativeModuleEnumDeclarationWithMembers | UnsafeAnyTypeAnnotation - | CompleteReservedTypeAnnotation - // Native Module event emitters and methods - | ObjectTypeAnnotation< - Nullable | EventEmitterTypeAnnotation, - >; + | ArrayTypeAnnotation + | ObjectTypeAnnotation + | CompleteReservedTypeAnnotation; From cadb1d7cda9d4440a8788de341932f902aa886ee Mon Sep 17 00:00:00 2001 From: Eli White Date: Fri, 3 Jan 2025 23:43:09 -0800 Subject: [PATCH 3/3] Separate component array types and command array types (#48474) Summary: The previous definition said that you could put prop types into commands, which definitely isn't allowed. For example, the schema would have allowed `WithDefault` types. ``` interface NativeCommands { +methodInt: (viewRef: React.ElementRef, a: WithDefault) => void; } ``` This change separates out the things that are allowed in commands from what's allowed in props. Commands should be very similar to what's allowed in native modules, but it isn't exact enough to be able to merge those. Differential Revision: D67806818 --- packages/react-native-codegen/src/CodegenSchema.d.ts | 10 +++++++++- packages/react-native-codegen/src/CodegenSchema.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index 9d121f6a75cb9c..889dce86f57f70 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -142,6 +142,14 @@ export type ComponentArrayTypeAnnotation = ArrayTypeAnnotation< | ArrayTypeAnnotation> >; +export type ComponentCommandArrayTypeAnnotation = ArrayTypeAnnotation< + | BooleanTypeAnnotation + | StringTypeAnnotation + | DoubleTypeAnnotation + | FloatTypeAnnotation + | Int32TypeAnnotation +>; + export interface ArrayTypeAnnotation { readonly type: 'ArrayTypeAnnotation'; readonly elementType: T; @@ -206,7 +214,7 @@ export type CommandParamTypeAnnotation = | DoubleTypeAnnotation | FloatTypeAnnotation | StringTypeAnnotation - | ComponentArrayTypeAnnotation; + | ComponentCommandArrayTypeAnnotation; export interface ReservedTypeAnnotation { readonly type: 'ReservedTypeAnnotation'; diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index e7fc38e4f3a919..f76b1d03d4034d 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -158,6 +158,14 @@ export type ComponentArrayTypeAnnotation = ArrayTypeAnnotation< | ArrayTypeAnnotation>, >; +export type ComponentCommandArrayTypeAnnotation = ArrayTypeAnnotation< + | BooleanTypeAnnotation + | StringTypeAnnotation + | DoubleTypeAnnotation + | FloatTypeAnnotation + | Int32TypeAnnotation, +>; + export type ArrayTypeAnnotation<+T> = $ReadOnly<{ type: 'ArrayTypeAnnotation', elementType: T, @@ -222,7 +230,7 @@ export type CommandParamTypeAnnotation = | DoubleTypeAnnotation | FloatTypeAnnotation | StringTypeAnnotation - | ComponentArrayTypeAnnotation; + | ComponentCommandArrayTypeAnnotation; export type ReservedTypeAnnotation = $ReadOnly<{ type: 'ReservedTypeAnnotation',