TypeScript · Junior · Question 46 of 75
What happens when you pass an object literal with an extra property?
type User = { name: string };
const u: User = { name: 'Ann', age: 30 };- ✓Correct answer: An error: literals are subject to excess property checks
- 2It's fine: extra properties are always allowed
- 3The
ageproperty is silently removed during compilation
Explanation
The excess property check applies only to fresh object literals - it's protection against typos. If you first put the object into a variable and then assign it, there's no error (structural compatibility). The compiler doesn't remove anything.