Skip to content

Commit e036555

Browse files
committed
unions
1 parent 08df039 commit e036555

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/jsxpression/src/codegen/schema/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function mapSchemaTypeToTypeScript(prop: any, depth: number = 0): string
2828
return "object";
2929
case "function":
3030
return "(...args: any[]) => any";
31+
case "union": {
32+
return `${prop.shape.map((p: any) => mapSchemaTypeToTypeScript(p)).join(" | ")}`;
33+
}
3134
default:
3235
console.warn(`Unknown schema type: ${prop.type}`);
3336
return "any";

packages/jsxpression/src/schema.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export type ObjectPropertySchema = {
3636
shape: Record<string, PropertySchema>;
3737
};
3838

39+
export type UnionPropertySchema = {
40+
type: "union";
41+
description?: string;
42+
required?: boolean;
43+
shape: ReadonlyArray<PropertySchema>;
44+
};
45+
3946
export type ArrayPropertySchema = {
4047
type: "array";
4148
description?: string;
@@ -49,7 +56,8 @@ export type PropertySchema =
4956
| BooleanPropertySchema
5057
| FunctionPropertySchema
5158
| ObjectPropertySchema
52-
| ArrayPropertySchema;
59+
| ArrayPropertySchema
60+
| UnionPropertySchema;
5361

5462
export type ElementSchema = {
5563
description?: string;

0 commit comments

Comments
 (0)