The data to verify (raw response from Synthetika)
True if the data is a SynthetikaProductPrice, false otherwise
const product = { price: { gross: { final: "100" }, net: { final: "90" } } };
assertIsSynthetikaProductPrice(product.price.gross);
assertIsSynthetikaProductPrice(product.price.net);
console.log(product.price.gross.final);
export function assertIsSynthetikaProductPrice(
data: unknown,
): asserts data is SynthetikaProductPrice {
if (!data || typeof data !== 'object') {
console.log('isSynthetikaProductPrice: data is falsey or not an object');
throw new Error('isSynthetikaProductPrice: data is falsey or not an object');
}
if (!isSynthetikaProductPrice(data)) {
console.log('isSynthetikaProductPrice: data is missing base or final');
throw new Error('isSynthetikaProductPrice: data is missing base or final');
}
}
This can be used to verify the .price.gross and .price.net fields of a SynthetikaProduct