Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createTypeAlias leverages referenced/exported types #89

Open
opiepj opened this issue Jul 10, 2024 · 4 comments
Open

createTypeAlias leverages referenced/exported types #89

opiepj opened this issue Jul 10, 2024 · 4 comments

Comments

@opiepj
Copy link

opiepj commented Jul 10, 2024

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;
    };
};
@lightninglu10
Copy link

Anyone have any idea if this is possible or not?

@yuriibut
Copy link

yuriibut commented Oct 8, 2024

+1

@lightninglu10
Copy link

It's not possible using this library here, but we just built a system to do it internally.

@mathcovax
Copy link

mathcovax commented Nov 20, 2024

Hello @opiepj, feel free to check out this library zod-to-typescript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants