diff --git a/packages/react-native-codegen/src/CodegenSchema.d.ts b/packages/react-native-codegen/src/CodegenSchema.d.ts index 2d28bbfe7e271c..d5ab6ef8669078 100644 --- a/packages/react-native-codegen/src/CodegenSchema.d.ts +++ b/packages/react-native-codegen/src/CodegenSchema.d.ts @@ -26,6 +26,10 @@ export interface FloatTypeAnnotation { readonly type: 'FloatTypeAnnotation'; } +export interface NumberTypeAnnotation { + readonly type: 'NumberTypeAnnotation'; +} + export interface BooleanTypeAnnotation { readonly type: 'BooleanTypeAnnotation'; } @@ -42,6 +46,21 @@ export interface VoidTypeAnnotation { readonly type: 'VoidTypeAnnotation'; } +export interface NumberLiteralTypeAnnotation { + readonly type: 'NumberLiteralTypeAnnotation'; + readonly value: number; +} + +export interface StringLiteralTypeAnnotation { + readonly type: 'StringLiteralTypeAnnotation'; + readonly value: string; +} + +export interface BooleanLiteralTypeAnnotation { + readonly type: 'BooleanLiteralTypeAnnotation'; + readonly value: boolean; +} + export interface ObjectTypeAnnotation { readonly type: 'ObjectTypeAnnotation'; readonly properties: readonly NamedShape[]; @@ -49,6 +68,18 @@ export interface ObjectTypeAnnotation { readonly baseTypes?: readonly string[] | undefined; } +export interface UnionTypeAnnotation { + readonly type: 'UnionTypeAnnotation'; + readonly types: readonly T[]; +} + +// TODO(T72031674): TupleTypeAnnotation is added for parity with UnionTypeAnnotation +// to support future implementation. Currently limited to String and Number literals. +export interface TupleTypeAnnotation { + readonly type: 'TupleTypeAnnotation'; + readonly types: StringLiteralTypeAnnotation | NumberLiteralTypeAnnotation; +} + export interface MixedTypeAnnotation { readonly type: 'MixedTypeAnnotation'; } @@ -309,6 +340,12 @@ export interface StringLiteralUnionTypeAnnotation { readonly types: NativeModuleStringLiteralTypeAnnotation[]; } +export type NumberLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + +export type BooleanLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + export interface NativeModuleNumberTypeAnnotation { readonly type: 'NumberTypeAnnotation'; } @@ -374,6 +411,15 @@ export type UnionTypeAnnotationMemberType = | 'ObjectTypeAnnotation' | 'StringTypeAnnotation'; +export type NativeModuleUnionTypeAnnotationMemberType = + | NativeModuleObjectTypeAnnotation + | StringLiteralTypeAnnotation + | NumberLiteralTypeAnnotation + | BooleanLiteralTypeAnnotation + | BooleanTypeAnnotation + | StringTypeAnnotation + | NumberTypeAnnotation; + export interface NativeModuleUnionTypeAnnotation { readonly type: 'UnionTypeAnnotation'; readonly memberType: UnionTypeAnnotationMemberType; diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 99299dafc3c043..bc8f9cdcb78047 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -30,6 +30,10 @@ export type FloatTypeAnnotation = $ReadOnly<{ type: 'FloatTypeAnnotation', }>; +export type NumberTypeAnnotation = $ReadOnly<{ + type: 'NumberTypeAnnotation', +}>; + export type BooleanTypeAnnotation = $ReadOnly<{ type: 'BooleanTypeAnnotation', }>; @@ -52,11 +56,22 @@ export type StringLiteralTypeAnnotation = $ReadOnly<{ value: string, }>; +export type BooleanLiteralTypeAnnotation = $ReadOnly<{ + type: 'BooleanLiteralTypeAnnotation', + value: boolean, +}>; + export type StringLiteralUnionTypeAnnotation = $ReadOnly<{ type: 'StringLiteralUnionTypeAnnotation', types: $ReadOnlyArray, }>; +export type NumberLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + +export type BooleanLiteralUnionTypeAnnotation = + UnionTypeAnnotation; + export type VoidTypeAnnotation = $ReadOnly<{ type: 'VoidTypeAnnotation', }>; @@ -68,6 +83,18 @@ export type ObjectTypeAnnotation<+T> = $ReadOnly<{ baseTypes?: $ReadOnlyArray, }>; +export type UnionTypeAnnotation<+T> = $ReadOnly<{ + type: 'UnionTypeAnnotation', + types: $ReadOnlyArray, +}>; + +// TODO(T72031674): TupleTypeAnnotation is added for parity with UnionTypeAnnotation +// to support future implementation. Currently limited to String and Number literals. +export type TupleTypeAnnotation = $ReadOnly<{ + type: 'TupleTypeAnnotation', + types: StringLiteralTypeAnnotation | NumberLiteralTypeAnnotation, +}>; + export type MixedTypeAnnotation = $ReadOnly<{ type: 'MixedTypeAnnotation', }>; @@ -363,6 +390,15 @@ export type UnionTypeAnnotationMemberType = | 'ObjectTypeAnnotation' | 'StringTypeAnnotation'; +export type NativeModuleUnionTypeAnnotationMemberType = + | NativeModuleObjectTypeAnnotation + | StringLiteralTypeAnnotation + | NumberLiteralTypeAnnotation + | BooleanLiteralTypeAnnotation + | BooleanTypeAnnotation + | StringTypeAnnotation + | NumberTypeAnnotation; + export type NativeModuleUnionTypeAnnotation = $ReadOnly<{ type: 'UnionTypeAnnotation', memberType: UnionTypeAnnotationMemberType,