TypeScript · Senior · Question 37 of 75
What does the exactOptionalPropertyTypes flag change?
- ✓Correct answer:
{ a?: string }no longer accepts an explicita: undefined - 2It makes all optional properties required
- 3It forbids optional properties in interfaces
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.