Skip to content

Possible Incomplete Records Example? #1651

Discussion options

You must be logged in to vote

It probably should look something like this

const userSchema = z.object( { name: z.string() } )
const userStoreSchema = z.record( userSchema )

type UserStore = z.infer<typeof userStoreSchema>
// type UserStore = { [ x: string ]: { name: string } }

const userStore: UserStore = {}

userStore[ '77d2586b-9e8e-4ecf-8b21-ea7e0530eadd' ] = {
    name: 'Carlotta',
}
console.log( userStoreSchema.safeParse( userStore ).success ) // true

userStore[ '77d2586b-9e8e-4ecf-8b21-ea7e0530eadd' ] = {
    whatever: 'Ice cream sundae',
}
console.log( userStoreSchema.safeParse( userStore ).success ) // false

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@antontolken
Comment options

Comment options

You must be logged in to vote
1 reply
@messenjer
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
documentation Improvements or additions to documentation
3 participants