ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...
    • Type guard to validate if an unknown value is a valid WooCommerce SearchResponse. Checks if the value is an array and all items are valid SearchResponseItems.

      Parameters

      • response: unknown

        Value to validate

      Returns response is WooCommerceSearchResponse

      Type predicate indicating if the value is a valid SearchResponse

      // Valid search response
      const validResponse = [
      {
      id: 123,
      name: "Sodium Chloride",
      type: "simple",
      // ... other required properties
      prices: { price: "29.99", currency_code: "USD" }
      }
      ];

      if (isSearchResponse(validResponse)) {
      console.log('Valid search response with', validResponse.length, 'items');
      }
      export function isSearchResponse(response: unknown): response is WooCommerceSearchResponse {
      if (!Array.isArray(response)) {
      return false;
      }

      return response.every((item) => isSearchResponseItem(item));
      }