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

    Function isScienceLabAttributeResponse

    • Type guard for the ScienceLab (BigCommerce) product-attributes AJAX response. Narrows an unknown parsed value to ScienceLabAttributeResponse by requiring that it be an object carrying a data object. The variant price is read from data.price.without_tax.value, which callers still null-check.

      Parameters

      • value: unknown

        The parsed AJAX response to test

      Returns value is ScienceLabAttributeResponse

      True when value carries a data object

      const parsed = await this.httpPostJson({ path, body });
      if (isScienceLabAttributeResponse(parsed)) {
      const price = parsed.data?.price?.without_tax?.value;
      }
      export function isScienceLabAttributeResponse(
      value: unknown,
      ): value is ScienceLabAttributeResponse {
      return isPopulatedObject(value) && isPopulatedObject(value.data);
      }