Is there a way to make TypeScript compiler produce an error when a function is called with an argument that can be both of the union type cases? Example:
interface Name {
name: string
}
interface Email {
email: string
}
type NameOrEmail = Name | Email
function print(p: NameOrEmail) {
console.log(p)
}
print({name: 'alice'}) // Works
print({email: 'alice'}) // Works
print({email: 'alice', name: 'alice'}) // Works, but I'd like it to fail
print({email: 'alice', age: 33}) // Doesn't work