The data to verify (raw response from Synthetika)
True if the data is a SynthetikaSearchResponse, false otherwise
const response = await fetch("https://synthetikaeu.com/webapi/front/en_US/products/usd/search/sodium%20chloride");
assertIsSynthetikaSearchResponse(response);
const data = await response.json();
if (isSynthetikaSearchResponse(data)) {
console.log(data.count);
}
export function assertIsSynthetikaSearchResponse(
data: unknown,
): asserts data is SynthetikaSearchResponse {
if (!data || typeof data !== 'object') {
throw new Error('isSynthetikaSearchResponse: data is falsey or not an object');
}
if (!isSynthetikaSearchResponse(data)) {
throw new Error('isSynthetikaSearchResponse: data is not a SynthetikaSearchResponse');
}
}
This can be used to check if a SynthetikaSearchResponse is valid