How to extract tuple from array of objects for Zod enums?
export const PLANS = [
{
id: "0",
name: "free",
price: 0,
description: "Free Video Stream",
},
{
id: "price_1Nd",
name: "basic",
price: 5,
description: "Basic Video Stream",
},
{
id: "price_1Nd",
name: "standard",
price: 10,
description: "Standard Video Stream",
},
{
id: "price_1Nd",
name: "premium",
price: 20,
description: "Premium Video Stream",
},
] as const
const planNames = PLANS.map((plan) => plan.name)
// ("free" | "basic" | "standard" | "premium")[] what I get
// ["free", "basic", "standard", "premium"] what I wantexport const PLANS = [
{
id: "0",
name: "free",
price: 0,
description: "Free Video Stream",
},
{
id: "price_1Nd",
name: "basic",
price: 5,
description: "Basic Video Stream",
},
{
id: "price_1Nd",
name: "standard",
price: 10,
description: "Standard Video Stream",
},
{
id: "price_1Nd",
name: "premium",
price: 20,
description: "Premium Video Stream",
},
] as const
const planNames = PLANS.map((plan) => plan.name)
// ("free" | "basic" | "standard" | "premium")[] what I get
// ["free", "basic", "standard", "premium"] what I wantI need this for zod validation. Currently, I'm doing this way.
z.object({
stripeProductId: z.string(),
planName: z.enum(["free", "basic", "standard", "premium"]),
}), z.object({
stripeProductId: z.string(),
planName: z.enum(["free", "basic", "standard", "premium"]),
}),