Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,42 @@ function getObjectTypeAnnotations(
if (!isTypeAlias) {
return;
}
const parent = parser.nextNodeForTypeAlias(value);
let parent = parser.nextNodeForTypeAlias(value);
// Unwrap $ReadOnly/Readonly wrappers to get the inner object type
if (
parent.type === 'GenericTypeAnnotation' &&
(parent.id?.name === '$ReadOnly' || parent.id?.name === 'Readonly') &&
parent.typeParameters?.params?.length === 1
) {
parent = parent.typeParameters.params[0];
} else if (
parent.type === 'TSTypeReference' &&
parent.typeName?.name === 'Readonly' &&
parent.typeParameters?.params?.length === 1
) {
parent = parent.typeParameters.params[0];
}
if (
parent.type !== 'ObjectTypeAnnotation' &&
parent.type !== 'TSTypeLiteral'
) {
return;
}
const typeProperties = parser
.getAnnotatedElementProperties(value)
.map(prop =>
parseObjectProperty(
parent,
prop,
hasteModuleName,
types,
aliasMap,
{}, // enumMap
tryParse,
true, // cxxOnly
prop?.optional || false,
translateTypeAnnotation,
parser,
),
);
const typeProperties = (parent.properties ?? parent.members).map(prop =>
parseObjectProperty(
parent,
prop,
hasteModuleName,
types,
aliasMap,
{}, // enumMap
tryParse,
true, // cxxOnly
prop?.optional || false,
translateTypeAnnotation,
parser,
),
);
aliasMap[key] = {
type: 'ObjectTypeAnnotation',
properties: typeProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export type UnionFloat = 1.44 | 2.88 | 5.76;
export type UnionString = 'One' | 'Two' | 'Three';
export type UnionObject = {value: number} | {low: string};

export type ConstantsStruct = {
export type ConstantsStruct = Readonly<{
const1: boolean,
const2: number,
const3: string,
};
}>;

export type ObjectStruct = {
a: number,
Expand Down
Loading