Skip to content
46 changes: 46 additions & 0 deletions packages/react-native-codegen/src/CodegenSchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export interface FloatTypeAnnotation {
readonly type: 'FloatTypeAnnotation';
}

export interface NumberTypeAnnotation {
readonly type: 'NumberTypeAnnotation';
}

export interface BooleanTypeAnnotation {
readonly type: 'BooleanTypeAnnotation';
}
Expand All @@ -42,13 +46,40 @@ 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<T> {
readonly type: 'ObjectTypeAnnotation';
readonly properties: readonly NamedShape<T>[];
// metadata for objects that generated from interfaces
readonly baseTypes?: readonly string[] | undefined;
}

export interface UnionTypeAnnotation<T> {
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';
}
Expand Down Expand Up @@ -309,6 +340,12 @@ export interface StringLiteralUnionTypeAnnotation {
readonly types: NativeModuleStringLiteralTypeAnnotation[];
}

export type NumberLiteralUnionTypeAnnotation =
UnionTypeAnnotation<NumberLiteralTypeAnnotation>;

export type BooleanLiteralUnionTypeAnnotation =
UnionTypeAnnotation<BooleanLiteralTypeAnnotation>;

export interface NativeModuleNumberTypeAnnotation {
readonly type: 'NumberTypeAnnotation';
}
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export type FloatTypeAnnotation = $ReadOnly<{
type: 'FloatTypeAnnotation',
}>;

export type NumberTypeAnnotation = $ReadOnly<{
type: 'NumberTypeAnnotation',
}>;

export type BooleanTypeAnnotation = $ReadOnly<{
type: 'BooleanTypeAnnotation',
}>;
Expand All @@ -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<StringLiteralTypeAnnotation>,
}>;

export type NumberLiteralUnionTypeAnnotation =
UnionTypeAnnotation<NumberLiteralTypeAnnotation>;

export type BooleanLiteralUnionTypeAnnotation =
UnionTypeAnnotation<BooleanLiteralTypeAnnotation>;

export type VoidTypeAnnotation = $ReadOnly<{
type: 'VoidTypeAnnotation',
}>;
Expand All @@ -68,6 +83,18 @@ export type ObjectTypeAnnotation<+T> = $ReadOnly<{
baseTypes?: $ReadOnlyArray<string>,
}>;

export type UnionTypeAnnotation<+T> = $ReadOnly<{
type: 'UnionTypeAnnotation',
types: $ReadOnlyArray<T>,
}>;

// 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',
}>;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -396,6 +432,7 @@ export type NativeModuleBaseTypeAnnotation =
| StringLiteralUnionTypeAnnotation
| NativeModuleNumberTypeAnnotation
| NumberLiteralTypeAnnotation
| BooleanLiteralTypeAnnotation
| Int32TypeAnnotation
| DoubleTypeAnnotation
| FloatTypeAnnotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'use strict';

import type {
BooleanLiteralTypeAnnotation,
BooleanTypeAnnotation,
DoubleTypeAnnotation,
FloatTypeAnnotation,
Expand Down Expand Up @@ -65,6 +66,7 @@ export type StructTypeAnnotation =
| StringLiteralUnionTypeAnnotation
| NativeModuleNumberTypeAnnotation
| NumberLiteralTypeAnnotation
| BooleanLiteralTypeAnnotation
| Int32TypeAnnotation
| DoubleTypeAnnotation
| FloatTypeAnnotation
Expand Down
Loading