TypeScript · Senior · Question 65 of 75
Why do excess property checks miss errors in this case?
const input = { name: 'A', nmae: 'typo' };
const user: User = input; // no error- ✓Correct answer: Excess property checks apply only to fresh object literals, not to variables of a wider type
- 2TypeScript ignores typos
- 3
Usermust be an interface for the check
Explanation
TypeScript has no exact object types. Assign literals directly, or use satisfies at the literal to keep the check.