The value to validate
Type predicate indicating if the value is a valid currency code
const validCode = "USD";
if (isCurrencyCode(validCode)) {
console.log("Valid currency code:", validCode);
} else {
console.log("Invalid currency code:", validCode);
}
export function isCurrencyCode(code: unknown): code is CurrencyCode {
return typeof code === "string" && Object.values(CURRENCY_SYMBOL_MAP).includes(code);
}
Type guard to validate if a value is a valid currency code. Checks if the value is a string and if it is in the CURRENCY_SYMBOL_MAP.