ChemPal Documentation - v1.6.0
    Preparing search index...
    • Type guard for a cached product-data record — the plain object produced by ProductBuilder.dump() and round-tripped through the product-detail cache. Narrows an unknown (or Record<string, unknown>) cache read to Partial<T> so it can be handed to ProductBuilder.setData without an assertion.

      The check is intentionally structural (a non-null, non-array object) rather than a full-schema validation: setData already routes every key through its own validating setter and silently drops any field that fails, so validating individual fields here would only risk rejecting an otherwise-usable product.

      Type Parameters

      Parameters

      • value: unknown

        The value read back from the product-detail cache

      Returns value is Partial<T>

      Type predicate indicating the value is a Partial<T> record

      const cached = await this.cache.getCachedProductData(key);
      if (isCachedProductData<Product>(cached)) {
      product.setData(cached); // cached is Partial<Product>
      }
      export function isCachedProductData<T extends Product = Product>(
      value: unknown,
      ): value is Partial<T> {
      return typeof value === 'object' && value !== null && !Array.isArray(value);
      }