Skip to content

How make all properties of a z.object "non-optional/nullable" #1474

Answered by JacobWeisenburger
zomars asked this question in Q&A
Discussion options

You must be logged in to vote

Let me know if this works for you.

export const _AvailabilityModel = z.object( {
    id: z.number().int(),
    userId: z.number().int().nullish(),
    eventTypeId: z.number().int().nullish(),
    days: z.number().int().array(),
    startTime: z.date(),
    endTime: z.date().optional(),
    date: z.date().nullish(),
    scheduleId: z.number().int().nullish(),
} )
type _AvailabilityModel = z.infer<typeof _AvailabilityModel>
// type _AvailabilityModel = {
//     userId?: number | null | undefined
//     eventTypeId?: number | null | undefined
//     endTime?: Date | undefined
//     date?: Date | null | undefined
//     scheduleId?: number | null | undefined
//     id: number
//     days: nu…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JacobWeisenburger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants