mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Suport type aliases for TM getConstants() return type (#39136)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39136 ## Changelog: [Internal] - `getConstants()` method for TM was enforced to only use object literals for the return type specs. This limits flexibility, in particular those data structures can't be consequently exported and picked up by codegen (not even mentioning the potential need for copypasting those obejct literals around). This relaxes this restriction. Note that I've been digging into the development history in order to find out whether there was any particular historical reason for such a limitation, but couldn't find any, so I assume it was rather incidental. Reviewed By: christophpurrer Differential Revision: D48620652 fbshipit-source-id: 92d6ba531fc99fb9b25b4957ae123e7832f44ee4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2692f206a6
commit
3c6bf7bf32
Vendored
+13
-3
@@ -459,14 +459,24 @@ function serializeConstantsProtocolMethods(
|
||||
);
|
||||
}
|
||||
|
||||
const {returnTypeAnnotation} = propertyTypeAnnotation;
|
||||
let {returnTypeAnnotation} = propertyTypeAnnotation;
|
||||
|
||||
if (returnTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
||||
// The return type is an alias, resolve it to get the expected undelying object literal type
|
||||
returnTypeAnnotation = resolveAlias(returnTypeAnnotation.name);
|
||||
}
|
||||
|
||||
if (returnTypeAnnotation.type !== 'ObjectTypeAnnotation') {
|
||||
throw new Error(
|
||||
`${hasteModuleName}.getConstants() may only return an object literal: {...}.`,
|
||||
`${hasteModuleName}.getConstants() may only return an object literal: {...}` +
|
||||
` or a type alias of such. Got '${propertyTypeAnnotation.returnTypeAnnotation.type}'.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (returnTypeAnnotation.properties.length === 0) {
|
||||
if (
|
||||
returnTypeAnnotation.type === 'ObjectTypeAnnotation' &&
|
||||
returnTypeAnnotation.properties.length === 0
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user