ts-to-zod icon indicating copy to clipboard operation
ts-to-zod copied to clipboard

Support nested namespaces

Open br0p0p opened this issue 2 years ago • 0 comments

Feature description

I saw namespace support was added a while back but using ts-to-zod on my project doesn't generate schemas from types within nested namespaces.

I am willing to implement this feature if you'll point me in the right direction.

Input

type Post = {
	id: string;
	authorId: string;
	title: string;
	body: string;
}

export namespace v1 {
	export namespace GetPosts {
		export type RequestParams = { authorId: string };
		export type ResponseBody = { posts: Post[] };
	}
}

Output

// This type is generated as expected
const postSchema = z.object({ 
	id: z.string(),
	authorId: z.string(),
	title: z.string(), 
	body: z.string() 
});

// These are not generated
const v1GetPostsRequestParamsSchema = z.object({ authorId: z.string() });

const v1GetPostsResponseBodySchema = z.object({ posts: postSchema.array() });

br0p0p avatar Nov 17 '22 18:11 br0p0p