How would someone define an empty array? #2201
-
eg: type ObjectOfEmptyArrays = Record<string, []>; How would someone do this in zod? z.object({}).catchall(z.array(z.????)); |
Beta Was this translation helpful? Give feedback.
Answered by
JacobWeisenburger
Mar 16, 2023
Replies: 2 comments 13 replies
-
In typescript so, you can use the following definition of schema: z.object({}).catchall(z.array(z.any())); or z.object({}).catchall(z.array(z.uknown())); |
Beta Was this translation helpful? Give feedback.
5 replies
-
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 |
Beta Was this translation helpful? Give feedback.
8 replies
Answer selected by
WORMSS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm pretty sure what you are looking for is an empty tuple.