-
-
Couldn't load subscription status.
- Fork 7
Open
Description
Hi there!
When using toZod on this interface:
export type Position = [number, number];
export interface Polygon {
type: "Polygon";
coordinates: [Position[],Position[]];
bbox?: [number, number, number, number] | [number, number, number, number, number, number]
}I stumble across the missing support for unions (#4), because I neither can use a tuple .or another, nor an array.
And I can't set a literal for "type", because toZod expects "never" instead of a literal.
I'd expect this to be a strict match for it:
export const polygonValidation = z.object({
type: z.literal('Polygon'),
coordinates: z
.array(z.array(z.tuple([z.number(), z.number()])).min(4))
.min(1)
.max(2),
bbox: z
.union([
z.tuple([z.number(), z.number(), z.number(), z.number()]),
z.tuple([
z.number(),
z.number(),
z.number(),
z.number(),
z.number(),
z.number(),
]),
])
.optional(),
});jahilliard, cdierkens, spg, ownadi, Twiggeh and 1 more
Metadata
Metadata
Assignees
Labels
No labels