TypeScript · Senior · Question 37 of 75

What does the exactOptionalPropertyTypes flag change?

Explanation

Without the flag, a?: string is equivalent to a?: string | undefined. With it, "no key" and "key present with value undefined" are distinguished, which matters for Object.keys, in and spread. If undefined is needed explicitly, write a?: string | undefined.

Further reading

Problem with a question

TypeScript · Senior · question 37

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