ChemPal Documentation - v1.15.1
    Preparing search index...

    Function isProductSelection

    • 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.

      Parameters

      • selection: unknown

        Object to validate as ProductSelection

      Returns selection is 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;
      }