Object to validate as ProductItem
Type predicate indicating if item is a valid ProductItem
// Valid product item
const validItem = {
id: "item_123",
formattedPrice: "$29.99",
price: 29.99,
optionsSelections: [1]
};
if (isProductItem(validItem)) {
console.log("Valid product item:", validItem.id);
console.log("Price:", validItem.formattedPrice);
}
export function isProductItem(item: unknown): item is ProductItem {
return v.safeParse(productItemSchema, item).success;
}
Type guard to validate if an object is a valid Wix ProductItem. Checks for the presence and correct types of all required item properties including ID, price, and ensures optionsSelections is a non-empty array.