Here I have a object and an interface, its shape is like this
interface OBJ {
firstName: string;
lastName: string;
}
const obj: OBJ = { firstName: "John", lastName: "Smith", random: 1 };
Here clearly TS compiler would error on 'random' does not exist in type 'OBJ'.
However if I have a function as this
const getNewObj = (obj: OBJ) => ({
fullName: obj.firstName + obj.lastName,
...obj
});
then I pass obj into this function
console.log(getNewObj(obj));
There is no error. How come?
Live demo: https://codesandbox.io/s/eager-joliot-s4j93?file=/src/index.ts:289-318