-
Notifications
You must be signed in to change notification settings - Fork 70
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
Improvements for using discriminatedUnion #270
Comments
Hey @Ilrilan, This is not implemented in the lib yet. We would need to give a hint to /**
* @discriminator type
*/
type MyApiResult = { type:'A', foo: string } | { type:'B', bar: number } | { type: 'C', baz: boolean } Would that make sense? |
Yes, this variant will be good solution. |
Hey! May such features be available via both JSDoc and some cli option? As an alternative way to pass these hints. This cli option may be just a path to a config file with such hints in some format (as it may appear to be messy to pass such a big instructions "as is" via cli). I'm asking about it because I have already auto-generated (swagger) ts file and I would prefer to not touch the file itself before applying ts-to-zod to it. Sure I can make such changes to my file "on fly" and pipe to ts-to-zod, but it may be not that user-friendly. 🙂 Thanks in advance! |
Hello @Artemnsk, What would be your suggestion for the config part? export type Config = {
//...
/**
* A record of discriminated unions with their corresponding type names.
*/
discriminatedUnions?: Record<string, string>;
}; with instantiation as {
MyApiResult: "type"
} for instance? That could work, but only for named union types. |
cool, can't wait 😛 |
The |
Feature description
Sometimes we have a union types with discriminated union, Zod can parse this case with help of discriminator, boosting performance. Can i modify configuration of ts-to-zod for customizing result schema now, or this feature need some enchancements of tool code?
Input
Output
The text was updated successfully, but these errors were encountered: