I'm learning TypeScript programming, but I don't understand why a type can accept a subtype when used as a function parameter. I think the code below should give an error but it doesn't:
type Numbers = { x: number, y: number };
function add(arg: Numbers) {
return arg.x + arg.y;
}
type NumbersWithName = Numbers & { name: string }
const numbersWithName: NumbersWithName = { name: 'alice', x: 0, y: 1 };
add(numbersWithName); // No Error
const numbers: Numbers = { name: 'alice', x: 0, y: 1 }; // Error
If the logic in the add function does not welcome others attributes, what should I do? Is it unreasonable to do so?