Skip to content

Fix exactOptionalPropertyTypes not enforced through spread-with-terna…#63252

Closed
GokhanKabar wants to merge 1 commit intomicrosoft:mainfrom
GokhanKabar:fix/exactOptionalPropertyTypes-spread-ternary
Closed

Fix exactOptionalPropertyTypes not enforced through spread-with-terna…#63252
GokhanKabar wants to merge 1 commit intomicrosoft:mainfrom
GokhanKabar:fix/exactOptionalPropertyTypes-spread-ternary

Conversation

@GokhanKabar
Copy link

fixes #63240

When spreading a conditional expression like { ...(cond ? { x: obj.optProp } : {}) } where optProp is an optional property, the exactOptionalPropertyTypes check was silently bypassed.

The value of an optional property read (e.g. obj.optProp) has the internal type T | missingType. In getAnonymousPartialType, calling addOptionality on that type is a no-op because missingType is already the first union member, producing a spread type identical to the target's exact optional property type and suppressing the diagnostic.

Fix: when a required property's type contains missingType, normalize it to undefinedType before calling addOptionality, so the resulting type is T | undefined | missingType distinguishable from the target and the check fires.

…ry (#63240)

When spreading a conditional expression like `{ ...(cond ? { x: obj.optProp } : {}) }`
where `optProp` is an optional property, the exactOptionalPropertyTypes check was
silently bypassed.

The value of an optional property read (e.g. `obj.optProp`) has the internal type
`T | missingType`. In `getAnonymousPartialType`, calling `addOptionality` on that type
is a no-op because `missingType` is already the first union member, producing a spread
type identical to the target's exact optional property type and suppressing the diagnostic.

Fix: when a *required* property's type contains `missingType`, normalize it to
`undefinedType` before calling `addOptionality`, so the resulting type is
`T | undefined | missingType` — distinguishable from the target — and the check fires.
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Mar 14, 2026
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@GokhanKabar GokhanKabar deleted the fix/exactOptionalPropertyTypes-spread-ternary branch March 24, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Error from exactOptionalPropertyTypes not reported when using object spread with a ternary and optional property acces

2 participants