From this tutorial: A user-defined type guard function is a function that returns "arg is aType". For example:
function isCustomer(partner: any): partner is Customer {
return partner instanceof Customer;
}
function signContract(partner: BusinessPartner): string {
let message: string;
if (isCustomer(partner)) {
message = partner.isCreditAllowed() ? 'Sign a new contract with the customer' : 'Credit issue';
} else {
message = partner.isInShortList() ? 'Sign a new contract with the supplier' : 'Need to evaluate further';
}
return message;
}
Why is the return type of 'partner is Customer' advantageous over simply returning a boolean?