-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Description
Bug description
When generating schemas with enum that has default values, typescript errors occurs:
No overload matches this call.
Overload 1 of 2, '(def: MyEnum): ZodDefault<ZodEnum<typeof MyEnum>>', gave the following error.
Argument of type '"THREE"' is not assignable to parameter of type 'MyEnum'.
Overload 2 of 2, '(def: () => MyEnum): ZodDefault<ZodEnum<typeof MyEnum>>', gave the following error.
Argument of type 'string' is not assignable to parameter of type '() => MyEnum'.ts(2769)
8 myEnum: myEnumSchema.default('THREE')
~~~~~~~
Input
enum MyEnum {
One = 'ONE',
Three = 'Three'
}
interface MyType {
/**
* @default THREE
*/
myEnum: MyEnum
}Expected output
// Generated by ts-to-zod
import { z } from 'zod'
import { MyEnum } from './test'
export const myEnumSchema = z.enum(MyEnum)
export const myTypeSchema = z.object({
myEnum: myEnumSchema.default(MyEnum.Three)
})Actual output
// Generated by ts-to-zod
import { z } from 'zod'
import { MyEnum } from './test'
export const myEnumSchema = z.enum(MyEnum)
export const myTypeSchema = z.object({
myEnum: myEnumSchema.default('THREE')
})Versions
- "typescript": "~5.9.2",
- "zod": "^4.1.5"
- "ts-to-zod": "^4.0.0",
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels