Sanity Library Reference Docs
    Preparing search index...

    Function isImageWithAsset

    • Checks that an image value has an asset that a URL can be built from. Image fields can be saved before an asset is uploaded, and an asset-> projection returns null when the asset is missing, so TypeGen types asset as optional or nullable.

      Type Parameters

      Parameters

      • value: T | null | undefined

      Returns value is SanityImageWithAsset<T>

      if (isImageWithAsset(data?.cover)) {
      builder.image(data.cover).width(800).url()
      }