"Type 'undefined' is not assignable" errors after enabling exactOptionalPropertyTypes on a shared library
0 reputation · 23 Jun 2026, 14:48 UTC
After enabling exactOptionalPropertyTypes in a shared TypeScript library (assume TS 5.x), consumers that pass objects with explicitly-undefined optional properties now fail to compile with assignability errors such as Type 'undefined' is not assignable to type ... with 'exactOptionalPropertyTypes: true'. The flag is documented as opt-in and is not part of strict mode, so teams in the same monorepo compile the same interfaces under different rules.
The concrete goal is to decide on a consistent policy for optional properties across packages: some interfaces were written assuming prop?: T means "may be absent or undefined", while others intend "must be absent if not set". With the flag on, these two meanings diverge, and declaration files emitted from one package behave differently when consumed by another package with a different tsconfig.
Questions:
- Should
prop?: Tbe rewritten asprop?: T | undefinedeverywhere to stay compatible with both flag settings, or is it better to standardize the flag across all packages? - Does enabling the flag only in the library but not in consumers create unsound typing at package boundaries?
- Is there a documented reason the flag remains outside
strictmode that should influence the decision?