Skip to content
Latchkey

TS2375: exactOptionalPropertyTypes undefined mismatch - in CI

With exactOptionalPropertyTypes on, assigning undefined to an optional property is rejected unless the type explicitly allows undefined.

What this error means

Type-checking fails with TS2375 after enabling exactOptionalPropertyTypes, suggesting you add undefined to the target type.

tsc
src/opts.ts(6,3): error TS2375: Type '{ label: string | undefined; }' is not assignable to type 'Props' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the type of the target.

Common causes

How to fix it

Add undefined to the property type

  1. If undefined is a valid value, declare the property as type | undefined
ts
interface Props { label?: string | undefined }

Omit the key instead of assigning undefined

  1. Build the object without the key when there is no value rather than setting it to undefined

How to prevent it

  • Decide per property whether a present-undefined is meaningful; omit keys you do not have rather than passing undefined.

Frequently asked questions

What causes "TS2375 exactOptionalPropertyTypes"?
Type-checking fails with TS2375 after enabling exactOptionalPropertyTypes, suggesting you add undefined to the target type.
How do I fix TS2375 exactOptionalPropertyTypes?
Add undefined to the property type

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card