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
- 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
- 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
TS2412: exactOptionalPropertyTypes property assignment - in CIFix "error TS2412: Type 'undefined' is not assignable ... with exactOptionalPropertyTypes: true" when assigni…
TS2322: Type is not assignable - in CIFix "error TS2322: Type 'X' is not assignable to type 'Y'" when tsc runs in CI - a genuine type mismatch on a…
TS2532: Object is possibly undefined - in CIFix "error TS2532: Object is possibly 'undefined'" when tsc runs in CI - guard array/optional access before u…