Skip to content

Commit

Permalink
Promise annotations must specify their elementType (facebook#46727)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#46727

It makes scripts operating on the schema complicated when the elementType might be there or might not. Let's make it required, but VoidTypeAnnotation if it's unknown.

Arguably we shouldn't allow it to be unknown at all, but that's out of scope here.

Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D63616703

fbshipit-source-id: 290586384b911928e55344aa522bd296f23a074c
  • Loading branch information
elicwhite authored and facebook-github-bot committed Sep 30, 2024
1 parent ad380c0 commit 86cac68
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/react-native-codegen/src/CodegenSchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export interface NativeModuleTypeAliasTypeAnnotation {

export interface NativeModulePromiseTypeAnnotation {
readonly type: 'PromiseTypeAnnotation';
readonly elementType?: Nullable<NativeModuleBaseTypeAnnotation> | undefined;
readonly elementType: Nullable<NativeModuleBaseTypeAnnotation> | VoidTypeAnnotation;
}

export type UnionTypeAnnotationMemberType =
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export type NativeModuleTypeAliasTypeAnnotation = $ReadOnly<{

export type NativeModulePromiseTypeAnnotation = $ReadOnly<{
type: 'PromiseTypeAnnotation',
elementType?: Nullable<NativeModuleBaseTypeAnnotation>,
elementType: VoidTypeAnnotation | Nullable<NativeModuleBaseTypeAnnotation>,
}>;

export type UnionTypeAnnotationMemberType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const SCHEMA_WITH_TM_AND_FC: SchemaType = {
type: 'FunctionTypeAnnotation',
returnTypeAnnotation: {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
},
params: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ const SIMPLE_NATIVE_MODULES: SchemaType = {
type: 'FunctionTypeAnnotation',
returnTypeAnnotation: {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
},
params: [
{
Expand All @@ -472,6 +475,9 @@ const SIMPLE_NATIVE_MODULES: SchemaType = {
type: 'FunctionTypeAnnotation',
returnTypeAnnotation: {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
},
params: [
{
Expand Down Expand Up @@ -1365,6 +1371,9 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
type: 'FunctionTypeAnnotation',
returnTypeAnnotation: {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
},
params: [
{
Expand All @@ -1385,6 +1394,9 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
type: 'FunctionTypeAnnotation',
returnTypeAnnotation: {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
},
params: [
{
Expand All @@ -1411,6 +1423,9 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
type: 'FunctionTypeAnnotation',
returnTypeAnnotation: {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
},
params: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,10 @@ exports[`RN Codegen Flow Parser can generate fixture PROMISE_WITH_COMMONLY_USED_
'typeAnnotation': {
'type': 'FunctionTypeAnnotation',
'returnTypeAnnotation': {
'type': 'PromiseTypeAnnotation'
'type': 'PromiseTypeAnnotation',
'elementType': {
'type': 'VoidTypeAnnotation'
}
},
'params': []
}
Expand All @@ -2417,7 +2420,10 @@ exports[`RN Codegen Flow Parser can generate fixture PROMISE_WITH_COMMONLY_USED_
'typeAnnotation': {
'type': 'FunctionTypeAnnotation',
'returnTypeAnnotation': {
'type': 'PromiseTypeAnnotation'
'type': 'PromiseTypeAnnotation',
'elementType': {
'type': 'VoidTypeAnnotation'
}
},
'params': []
}
Expand All @@ -2428,7 +2434,10 @@ exports[`RN Codegen Flow Parser can generate fixture PROMISE_WITH_COMMONLY_USED_
'typeAnnotation': {
'type': 'FunctionTypeAnnotation',
'returnTypeAnnotation': {
'type': 'PromiseTypeAnnotation'
'type': 'PromiseTypeAnnotation',
'elementType': {
'type': 'VoidTypeAnnotation'
}
},
'params': []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ function emitPromise(
) {
return wrapNullable(nullable, {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
});
} else {
try {
Expand All @@ -335,6 +338,9 @@ function emitPromise(
} catch {
return wrapNullable(nullable, {
type: 'PromiseTypeAnnotation',
elementType: {
type: 'VoidTypeAnnotation',
},
});
}
}
Expand Down

0 comments on commit 86cac68

Please sign in to comment.