Skip to content

extending a ZodType #1870

Answered by JacobWeisenburger
reharik asked this question in Q&A
Jan 12, 2023 · 1 comments · 6 replies
Discussion options

You must be logged in to vote

Is this what you are looking for?

interface Address {
    id?: string
    addressText: string
    line1: string
    line2?: string
    city: string
    state: string
    postalCode: string
    country: string
}

interface Location extends Address {
    latitude: number
    longitude: number
    businessName?: string
}

const addressSchema = z.object( {
    id: z.string().optional(),
    addressText: z.string(),
    line1: z.string(),
    line2: z.string().optional(),
    city: z.string(),
    state: z.string(),
    postalCode: z.string(),
    country: z.string(),
} ) satisfies z.ZodType<Address>

const locationSchema = addressSchema.extend( {
    latitude: z.number(),
    longitude: z.number

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@JacobWeisenburger
Comment options

@reharik
Comment options

@reharik
Comment options

@alexanderhorner
Comment options

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
3 participants