From a6b76c0c51bf37a864b88d48775afbc1143eebde Mon Sep 17 00:00:00 2001 From: Marco Wang Date: Wed, 17 Dec 2025 18:45:46 -0800 Subject: [PATCH] Support Readonly in react-native-codegen (#54925) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54925 The lint is triggered in D89415612. Not sure what those file do but it seems a good fix Changelog: [General][Added] Support parsing `Readonly` for the new Flow utility types Reviewed By: SamChou19815 Differential Revision: D89418629 fbshipit-source-id: 34a2776711155dbd52046d55af18104e2eb32322 --- .../src/parsers/flow/components/componentsUtils.js | 8 ++++++-- .../src/parsers/flow/components/events.js | 3 ++- .../src/parsers/flow/modules/index.js | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js b/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js index c6e72d31601..c8f2d46ec2f 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js +++ b/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js @@ -45,7 +45,10 @@ function getTypeAnnotationForArray<+T>( // Resolve the type alias if it's not defined inline const objectType = getValueFromTypes(extractedTypeAnnotation, types); - if (objectType.id.name === '$ReadOnly') { + if ( + objectType.id.name === '$ReadOnly' || + objectType.id.name === 'Readonly' + ) { return { type: 'ObjectTypeAnnotation', properties: flattenProperties( @@ -247,7 +250,8 @@ function getTypeAnnotation<+T>( if ( typeAnnotation.type === 'GenericTypeAnnotation' && - parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly' + (parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly' || + parser.getTypeAnnotationName(typeAnnotation) === 'Readonly') ) { return { type: 'ObjectTypeAnnotation', diff --git a/packages/react-native-codegen/src/parsers/flow/components/events.js b/packages/react-native-codegen/src/parsers/flow/components/events.js index 4bea22f5695..7f241cd0af6 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/events.js +++ b/packages/react-native-codegen/src/parsers/flow/components/events.js @@ -62,6 +62,7 @@ function getPropertyType( case 'Float': return emitFloatProp(name, optional); case '$ReadOnly': + case 'Readonly': return getPropertyType( name, optional, @@ -187,7 +188,7 @@ function findEventArgumentsAndType( ): EventArgumentReturnType { throwIfEventHasNoName(typeAnnotation, parser); const name = parser.getTypeAnnotationName(typeAnnotation); - if (name === '$ReadOnly') { + if (name === '$ReadOnly' || name === 'Readonly') { return { argumentProps: typeAnnotation.typeParameters.params[0].properties, paperTopLevelNameDeprecated: paperName, diff --git a/packages/react-native-codegen/src/parsers/flow/modules/index.js b/packages/react-native-codegen/src/parsers/flow/modules/index.js index 6730a7ac18b..5d946f2404b 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -114,7 +114,8 @@ function translateTypeAnnotation( translateTypeAnnotation, ); } - case '$ReadOnly': { + case '$ReadOnly': + case 'Readonly': { assertGenericTypeAnnotationHasExactlyOneTypeParameter( hasteModuleName, typeAnnotation,