Allow NativeModule method return types to use type aliases
Summary: We already support type-aliases in our NativeModule method params. This diff extends the support to NativeModule method returns. **Note:** I need to see if I need to update the generators to handle this case. Will do that in this diff, after working through other higher priority stuff. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D22828839 fbshipit-source-id: cf5c756d3cacf067df217cdb6212946320a2d4be
This commit is contained in:
Родитель
ef145adb9d
Коммит
341e05ff62
|
@ -304,6 +304,11 @@ export type FunctionTypeAnnotationReturn =
|
|||
nullable: boolean,
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: ?$ReadOnlyArray<ObjectParamTypeAnnotation>,
|
||||
|}>
|
||||
| $ReadOnly<{|
|
||||
nullable: boolean,
|
||||
type: 'TypeAliasTypeAnnotation',
|
||||
name: string,
|
||||
|}>;
|
||||
|
||||
export type FunctionTypeAnnotationReturnArrayElementType =
|
||||
|
|
|
@ -200,7 +200,7 @@ type Foo = {|
|
|||
|
||||
export interface Spec extends TurboModule {
|
||||
// Exported methods.
|
||||
foo1: (x: Foo) => void;
|
||||
foo1: (x: Foo) => Foo;
|
||||
foo2: (x: Foo) => void;
|
||||
}
|
||||
|
||||
|
|
|
@ -940,8 +940,9 @@ Object {
|
|||
},
|
||||
],
|
||||
"returnTypeAnnotation": Object {
|
||||
"name": "Foo",
|
||||
"nullable": false,
|
||||
"type": "VoidTypeAnnotation",
|
||||
"type": "TypeAliasTypeAnnotation",
|
||||
},
|
||||
"type": "FunctionTypeAnnotation",
|
||||
},
|
||||
|
|
|
@ -244,6 +244,13 @@ function getReturnTypeAnnotation(
|
|||
);
|
||||
}
|
||||
case 'ObjectTypeAnnotation':
|
||||
if (returnType.type === 'GenericTypeAnnotation') {
|
||||
return {
|
||||
nullable,
|
||||
type: 'TypeAliasTypeAnnotation',
|
||||
name: returnType.id.name,
|
||||
};
|
||||
}
|
||||
return {
|
||||
nullable,
|
||||
type: 'ObjectTypeAnnotation',
|
||||
|
@ -323,7 +330,7 @@ function buildMethodSchema(
|
|||
|
||||
const returnTypeAnnotation = getReturnTypeAnnotation(
|
||||
name,
|
||||
getValueFromTypes(value.returnType, types),
|
||||
value.returnType,
|
||||
types,
|
||||
);
|
||||
return {
|
||||
|
|
Загрузка…
Ссылка в новой задаче