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
This commit is contained in:
Marco Wang
2025-12-17 18:45:46 -08:00
committed by meta-codesync[bot]
parent 3bf7a09ecb
commit a6b76c0c51
3 changed files with 10 additions and 4 deletions
@@ -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',
@@ -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,
@@ -114,7 +114,8 @@ function translateTypeAnnotation(
translateTypeAnnotation,
);
}
case '$ReadOnly': {
case '$ReadOnly':
case 'Readonly': {
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
hasteModuleName,
typeAnnotation,