mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
react-native-code-gen Add Union Type support for Java/ObjC TurboModules (#35312)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35312 Changelog: [General][Added] react-native-code-gen Add Union Type support for Java/ObjC TurboModules Reviewed By: javache Differential Revision: D41216605 fbshipit-source-id: d411abed66c694d855ede40725667cbc7067538f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
72d3da19ce
commit
2eccd59d7c
Vendored
+30
-8
@@ -357,13 +357,25 @@ function getReturnObjCType(
|
||||
`Unsupported enum return type for ${methodName}. Found: ${typeAnnotation.type}`,
|
||||
);
|
||||
}
|
||||
case 'UnionTypeAnnotation':
|
||||
switch (typeAnnotation.memberType) {
|
||||
case 'NumberTypeAnnotation':
|
||||
return wrapIntoNullableIfNeeded('NSNumber *');
|
||||
case 'ObjectTypeAnnotation':
|
||||
return wrapIntoNullableIfNeeded('NSDictionary *');
|
||||
case 'StringTypeAnnotation':
|
||||
// TODO: Can NSString * returns not be _Nullable?
|
||||
// In the legacy codegen, we don't surround NSSTring * with _Nullable
|
||||
return wrapIntoNullableIfNeeded('NSString *');
|
||||
default:
|
||||
throw new Error(
|
||||
`Unsupported union return type for ${methodName}, found: ${typeAnnotation.memberType}"`,
|
||||
);
|
||||
}
|
||||
case 'GenericObjectTypeAnnotation':
|
||||
return wrapIntoNullableIfNeeded('NSDictionary *');
|
||||
default:
|
||||
(typeAnnotation.type:
|
||||
| 'EnumDeclaration'
|
||||
| 'MixedTypeAnnotation'
|
||||
| 'UnionTypeAnnotation');
|
||||
(typeAnnotation.type: 'EnumDeclaration' | 'MixedTypeAnnotation');
|
||||
throw new Error(
|
||||
`Unsupported return type for ${methodName}. Found: ${typeAnnotation.type}`,
|
||||
);
|
||||
@@ -413,11 +425,21 @@ function getReturnJSType(
|
||||
`Unsupported return type for ${methodName}. Found: ${typeAnnotation.type}`,
|
||||
);
|
||||
}
|
||||
case 'UnionTypeAnnotation':
|
||||
switch (typeAnnotation.memberType) {
|
||||
case 'NumberTypeAnnotation':
|
||||
return 'NumberKind';
|
||||
case 'ObjectTypeAnnotation':
|
||||
return 'ObjectKind';
|
||||
case 'StringTypeAnnotation':
|
||||
return 'StringKind';
|
||||
default:
|
||||
throw new Error(
|
||||
`Unsupported return type for ${methodName}. Found: ${typeAnnotation.type}`,
|
||||
);
|
||||
}
|
||||
default:
|
||||
(typeAnnotation.type:
|
||||
| 'EnumDeclaration'
|
||||
| 'MixedTypeAnnotation'
|
||||
| 'UnionTypeAnnotation');
|
||||
(typeAnnotation.type: 'EnumDeclaration' | 'MixedTypeAnnotation');
|
||||
throw new Error(
|
||||
`Unsupported return type for ${methodName}. Found: ${typeAnnotation.type}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user