Skip to content

How would someone define an empty array? #2201

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

You must be logged in to vote

I'm pretty sure what you are looking for is an empty tuple.

const schema = z.object( {} ).catchall( z.tuple( [] ) )
type Data = z.infer<typeof schema>
// type Data = {} & {
//     [ k: string ]: []
// }

console.log(
    schema.safeParse( { 'test': [] } ).success
) // true
console.log(
    schema.safeParse( { 'test': [ 'I should be blank' ] } ).success
) // false

Replies: 2 comments 13 replies

Comment options

You must be logged in to vote
5 replies
@WORMSS
Comment options

@kostysh
Comment options

@kostysh
Comment options

@WORMSS
Comment options

@lionelmalletpro
Comment options

Comment options

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

@WORMSS
Comment options

@JacobWeisenburger
Comment options

@WORMSS
Comment options

@JacobWeisenburger
Comment options

Answer selected by WORMSS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants