Is there a method to enforce excess-property checking, not only for an inline object literal but also one derived from a variable?
For instance, let's say I have an interface and a function
interface Animal {
speciesName: string
legCount: number,
}
function serializeBasicAnimalData(a: Animal) {
// something
}
If I invoke
serializeBasicAnimalData({
legCount: 65,
speciesName: "weird 65-legged animal",
specialPowers: "Devours plastic"
})
I would receive an error -- which is desired in my scenario. I only want the function to accept a general animal description without additional details.
However, if I initially assign it to a variable, the error does not occur:
var weirdAnimal = {
legCount: 65,
speciesName: "weird 65-legged animal",
specialPowers: "Devours plastic"
};
serializeBasicAnimalData(weirdAnimal);
So, my question is: Is there a way to compel TypeScript to conduct "excess property checking" on the function parameter regardless of whether it's an inline object or an object previously assigned to a variable?