Why does TypeScript behave the way it does in my case?
If I directly type an object, it complains about properties which are not defined in the interface. But if I cast the object it allows do add any random properties not defined in the interface.
Best explained with an example:
interface House {
windows: number;
garden: boolean;
}
const house1: House = {
windows: 5,
garden: true,
garage: true // not allowed
};
const whatever = {
house2: <House> {
windows: 3,
garden: true,
garage: true // why is it here allowed?
}
};