The object to validate
Type predicate indicating if the object is a valid SearchResultItem
// Valid search result item
const validItem = {
label: "Sodium Chloride",
image: "nacl.jpg",
description: "High purity NaCl",
href: "/products/nacl"
};
if (isSearchResultItem(validItem)) {
console.log("Valid item:", validItem.label);
}
// Invalid search result item (missing properties)
const invalidItem = {
label: "Sodium Chloride",
image: "nacl.jpg"
// Missing description and href
};
if (!isSearchResultItem(invalidItem)) {
console.log("Invalid item - missing required properties");
}
// Invalid search result item (wrong type)
const wrongType = "not an object";
if (!isSearchResultItem(wrongType)) {
console.log("Invalid item - not an object");
}
Type guard to validate if an object matches the SearchResultItem structure. Checks for the presence and correct types of required properties in Onyxmet search results. Required properties: