The in operator narrows a union of object types by checking if a property exists. If 'password' in user is true, you know you have the password-based variant.
function needsPwd(u: { password: string } | { token: string }) {
return "password" in u;
}
Return a boolean so you can drive decisions using simple conditions.
Decide if an account requires a password.