The value to check
Type predicate indicating if the value is a valid ProductImage
// Valid image entry
if (isProductImage({ href: "https://example.com/a.jpg", type: "image" })) {
console.log('Valid product image');
}
// Invalid — unknown type
if (!isProductImage({ href: "https://example.com/a.jpg", type: "banner" })) {
console.log('Not a valid product image');
}
// Invalid — missing href
if (!isProductImage({ type: "thumbnail" })) {
console.log('Not a valid product image');
}
export function isProductImage(value: unknown): value is ProductImage {
return v.safeParse(productImageSchema, value).success;
}
Type guard to validate if a value is a valid product image entry. Checks for a string
hrefand atypeof either "image" or "thumbnail". Thehrefis only shape-checked here; the builder resolves it to an absolute URL (and drops the entry when it can't).