mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Support ReadonlyArray in react-native-codegen (#54924)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54924 The lint is triggered in D89415612. Not sure what those file do but it seems a good fix Changelog: [General][Added] Support parsing `ReadonlyArray` for the new Flow utility types Reviewed By: SamChou19815 Differential Revision: D89418033 fbshipit-source-id: ef227b344a693ec47dea86bbf34e0af17bad25fd
This commit is contained in:
1 parent
c7f433a413
commit
3bf7a09ecb
4 files changed
+12
-4
No files matched your search
@@ -105,11 +105,12 @@ function buildCommandSchema(
|
||||
break;
|
||||
case 'Array':
|
||||
case '$ReadOnlyArray':
|
||||
case 'ReadonlyArray':
|
||||
/* $FlowFixMe[invalid-compare] Error discovered during Constant
|
||||
* Condition roll out. See https://fburl.com/workplace/4oq3zi07. */
|
||||
if (!paramValue.type === 'GenericTypeAnnotation') {
|
||||
throw new Error(
|
||||
'Array and $ReadOnlyArray are GenericTypeAnnotation for array',
|
||||
'Array, $ReadOnlyArray and ReadonlyArray are GenericTypeAnnotation for array',
|
||||
);
|
||||
}
|
||||
returnType = {
|
||||
|
||||
+6
-2
@@ -58,7 +58,10 @@ function getTypeAnnotationForArray<+T>(
|
||||
};
|
||||
}
|
||||
|
||||
if (objectType.id.name === '$ReadOnlyArray') {
|
||||
if (
|
||||
objectType.id.name === '$ReadOnlyArray' ||
|
||||
objectType.id.name === 'ReadonlyArray'
|
||||
) {
|
||||
// We need to go yet another level deeper to resolve
|
||||
// types that may be defined in a type alias
|
||||
const nestedObjectType = getValueFromTypes(
|
||||
@@ -226,7 +229,8 @@ function getTypeAnnotation<+T>(
|
||||
|
||||
if (
|
||||
typeAnnotation.type === 'GenericTypeAnnotation' &&
|
||||
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnlyArray'
|
||||
(parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnlyArray' ||
|
||||
parser.getTypeAnnotationName(typeAnnotation) === 'ReadonlyArray')
|
||||
) {
|
||||
return {
|
||||
type: 'ArrayTypeAnnotation',
|
||||
|
||||
@@ -82,6 +82,7 @@ function getPropertyType(
|
||||
return emitMixedProp(name, optional);
|
||||
case 'ArrayTypeAnnotation':
|
||||
case '$ReadOnlyArray':
|
||||
case 'ReadonlyArray':
|
||||
return {
|
||||
name,
|
||||
optional,
|
||||
@@ -142,6 +143,7 @@ function extractArrayElementType(
|
||||
),
|
||||
};
|
||||
case '$ReadOnlyArray':
|
||||
case 'ReadonlyArray':
|
||||
const genericParams = typeAnnotation.typeParameters.params;
|
||||
if (genericParams.length !== 1) {
|
||||
throw new Error(
|
||||
|
||||
@@ -100,7 +100,8 @@ function translateTypeAnnotation(
|
||||
);
|
||||
}
|
||||
case 'Array':
|
||||
case '$ReadOnlyArray': {
|
||||
case '$ReadOnlyArray':
|
||||
case 'ReadonlyArray': {
|
||||
return emitArrayType(
|
||||
hasteModuleName,
|
||||
typeAnnotation,
|
||||
|
||||
Reference in new issue
Block a user