Object to validate as ProductSelection
Type predicate indicating if selection is a valid ProductSelection
// Valid product selection (string ID)
const validSelection = {
id: "opt_1",
value: "500g",
description: "500g Bottle",
key: "size",
inStock: true
};
if (isProductSelection(validSelection)) {
console.log("Valid selection:", validSelection.value);
console.log("In stock:", validSelection.inStock);
}
export function isProductSelection(selection: unknown): selection is ProductSelection {
return v.safeParse(productSelectionSchema, selection).success;
}
Type guard to validate if an object is a valid Wix ProductSelection. Checks for the presence and correct types of all required selection properties including ID (which can be string or number), value, description, key, and inStock.