zod-to-ts
zod-to-ts copied to clipboard
createTypeAlias leverages referenced/exported types
This possible? Be cool if we can leverage other type aliases.
Input:
export const BusSchema = z.object({
foo: z.string(),
bar: z.boolean().optional()
});
export const BazSchema = z.object({
boo: z.object({
one: z.number(),
two: z.number().optional()
})
});
export const TestSchema = z.object({
baz: BazSchema,
bus: BusSchema
});
const identifier = 'TestSchema';
const { node } = zodToTs(TestSchema, identifier);
const typeAlias = createTypeAlias(node, identifier);
return printNode(typeAlias);
Expected Output:
export type BusSchema = {
foo: string();
bar?: boolean();
}
export type BazSchema = {
boo: {
one: number;
two?: number;
}
}
export type TestSchema = {
baz: BazSchema;
bus: BusSchema;
}
Actual Output:
export type BazSchema = {
boo: {
one: number;
two?: number | undefined;
};
};
export type BusSchema = {
foo: string;
bar?: boolean | undefined;
}
export type TestSchema = {
baz: {
boo: {
one: number;
two?: number | undefined;
};
};
bus: {
foo: string;
bar?: boolean | undefined;
};
};