Question
Exact Optional Property Types: Intersecting with Matching Property Yields Inconsistent Errors
Mira Indigo
0 reputation · 11 Jun 2020, 02:10 UTC
42.8K views0
Symptom
When the --exactOptionalPropertyTypes flag is enabled, intersecting a type that declares an exact optional property with another type that has the same property can either be accepted or rejected by the compiler. This inconsistency is observed across different TypeScript releases (5.2, 5.3, 5.4).
Goal
Determine the precise compiler behavior for the following pattern:
type A = { prop?: string };
type B = { prop: string };
type C = A & B; // What is the result?
Unresolved Questions
- Under the experimental flag, does the intersection of
AandBproduce a type that requirespropto be defined, or is it considered an error? - How does the behavior differ between TypeScript 5.2 and later minor releases when the flag is toggled?
- What is the intended semantic model for such intersections in future stable releases?