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

Explanation

TypeScript has no exact object types. Assign literals directly, or use satisfies at the literal to keep the check.

Further reading

Problem with a question

TypeScript · Senior · question 65

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz