Skip to content

chore: enable exactOptionalPropertyTypes across the repository - #765

Merged
Menci merged 22 commits into
mainfrom
chore/exact-optional-property-types
Nov 24, 2026
Merged

Menci merged 22 commits into
mainfrom
chore/exact-optional-property-types

Conversation

@Menci

@Menci Menci commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Problem

Optional properties across the repository were typed as prop?: T, which TypeScript treats as T | undefined unless exactOptionalPropertyTypes is on. Code therefore wrote { key: undefined } and { key: value } interchangeably, although JSON, in, Object.hasOwn, Object.keys, spreads, and zod's output tell them apart. Several of those spots were real defects hidden by the loose typing.

Change

tsconfig.base.json enables exactOptionalPropertyTypes for every project. Each package states an absent value by omitting the key, and a type admits undefined only where the value genuinely passes through it:

  • Foundation, providers, gateway. Request inits are built through toRequestInit, signal and option bags admit undefined explicitly, and about 250 control-plane zod fields use .exactOptional(), so a parsed body carries only the keys a client sent. The dump limit is parsed with z.preprocess, and the flag-override schema rejects an explicit undefined (.exactOptional() paired with coercion produces unexpected values colinhacks/zod#6236).
  • Dashboard. Our own component props use prop?: T | undefined, the @types/react convention. Fluent non-slot props are omitted when absent. A validationState that was undefined is now 'none', which Fluent resolves it to whenever no message is shown. The model, alias-rule, announced-metadata, and pricing editors share FieldPatch<T>: undefined clears an optional field, and clearing a required field is a type error. A cleared field now leaves the draft and returns at a new key position when restored, so the discard guard compares drafts as canonical JSON.

Rewriting { key: maybeUndefined } as ...(value === undefined ? {} : { key: value }) is not neutral when the object also spreads a base that carries the key. The explicit undefined used to override the base, and the conditional spread lets the base value through. Three places depended on that override. Each now removes the key from the base before spreading, and a new test asserts the key is absent and fails without the fix:

  • The Responses fast-path expansion restamps sequence numbers from the stream sequencer, so no event keeps the expansion's own numbering.
  • The Codex catalog does not inherit the client catalog's max_context_window when the upstream states none.
  • Copilot's merged variants do not keep a base variant's raw limits or reasoning efforts when the merge yields none.

Dependency declarations that reject values their own sources produce are patched and documented in pnpm-workspace.yaml:

Package Patch Upstream
@fluentui/react-utilities Ref inference ignores the handler's undefined. Slot admits undefined, and ComponentState keeps root required. microsoft/fluentui#25993, closed unfixed
hono Backports JSONParsed keeping optional properties optional honojs/hono#5664, released in 4.13.20
@hono/node-server The ws stub admits the undefined that @types/ws declares —
rolldown Backports ExistingRawSourceMap admitting undefined. Vite pins ~1.1.5. rolldown/rolldown#10355, released in 1.2.19

Verification

  • tsc --noEmit passes in all 23 TypeScript projects, apps/web included.
  • ESLint passes on every changed file.
  • Named Vitest runs pass for the changed gateway, provider, protocol, and translate files. They include the new fast-path, Codex catalog, Copilot variant, dump-limit, and flag-override tests, plus 57 web test files (168 tests) covering the changed dashboard modules.
  • pnpm run build:web passes.
  • In a local demo, every dashboard page renders without a new console error. A custom upstream saved through the model editor (fields set, then cleared) persisted exactly the remaining fields. Alias rules and manual announced metadata saved the same way. The WinUI gallery's checked/defaultChecked warning also appears on main.
  • All 21 Verify jobs pass.

Menci added 22 commits November 24, 2026 23:40
@fluentui/react-utilities infers a component's ref element from
Required<Props>['onLostPointerCaptureCapture']. @types/react declares the
handler with an explicit | undefined, which Required keeps under
exactOptionalPropertyTypes, so every Fluent ref collapses to Ref<never>.
Inferring from NonNullable of the handler is equivalent without the flag
and restores the element type with it. The upstream report,
microsoft/fluentui#25993, was closed by the stale bot unfixed.
Under exactOptionalPropertyTypes an optional property no longer accepts an
explicit undefined. Foundation packages now either omit a field whose value
is absent or declare that a slot is threaded through as T | undefined.

FetchInit admits an undefined signal because every provider threads its
caller's AbortSignal | undefined into it, and toRequestInit lowers an init
onto the runtime fetch contract, dropping that undefined, for every runtime
fetcher. ClientResponseResource removes the undefined that reading an
optional key adds before stating its nullable keys, which keeps client
stream events assignable to the wide event union.
Provider call options that thread a caller's AbortSignal, plan fallback,
credential input, selection hint, or HTTP head now declare those slots as
T | undefined. Parsed results and upstream-metric displays omit a field
whose value is absent, and test fixtures drop fields by destructuring
rather than overwriting them with undefined.
The foundation change stamped expanded terminal events directly, but
openaiResponsesResultToEvents numbers its events from 0 and the stream
sequencer adopts any number an event already carries. An upstream error
notice ahead of the terminal therefore produced a repeated sequence number.
The expansion's own numbering is dropped before stamping again, and a test
pins the continuous sequence.
Control-plane, codec, dump, access-control, and alpha-search schemas declare
optional keys with exactOptional, so their inferred types match the hand-
written records they feed. A coercion or transform keeps an absent key
present under exactOptional, so the dump limit coerces only a present value
and flag overrides reject undefined before parsing.
colinhacks/zod#6236

Option bags that forward a caller's possibly absent value declare those
slots as T | undefined; constructed records, catalog entries, and web
search results omit absent fields; and the hono node-server WebSocket stub
is patched to admit the undefined its ws source types carry.
Give the synthesized window fields sole ownership of the response values. A private catalog that omits its maximum must not inherit the client catalog maximum.
Keep synthesized events on the stream sequence without removing their local number and asserting the remaining event type.
Carry the checked permission value through candidate selection and state the streaming request option in its type. This keeps both runtime guarantees visible to TypeScript.
Remove the aggregated keys from the base fields before applying the merged values so a missing result cannot preserve a raw null or nonnumeric limit.
The runtime instance always owns rfc. Declare the undefined value explicitly and assign it directly.
Exercise the default and supplied list limit through the route and check parsed upstreams retain the shape of omitted flag overrides.
Use the narrowed agent part type, explicitly check echoed tool choice, and share chat fixtures whose values are known to be present.
The fixture accepted an explicit undefined for every payload key behind a
canonical cast, so a test could silently erase the default model. Only the
top-level tools are ever cleared, so a dedicated withoutTools option states
that intent and the payload override returns to Partial.
slot.optional treats an undefined slot value as omitted, but Fluent's Slot
type admits only null, which also hides a slot that renders by default.
The react-utilities patch adds undefined to Slot so an optional slot prop
can forward an absent value under exactOptionalPropertyTypes.
hono's JSONParsed adds `| undefined` to every optional property of an RPC
response, so under exactOptionalPropertyTypes a response no longer assigns
to the type the server serialized it from. Backport the upstream fix
(honojs/hono#5664, released in 4.13.20) as a type-only patch of 4.12.22:
an optional property stays optional, and only a required property whose
value may be dropped from JSON gains `| undefined`.
Two more dependency declarations reject values their own sources produce
once exactOptionalPropertyTypes is on.

rolldown's ExistingRawSourceMap omits `| undefined` from optional fields
that magic-string's SourceMap sets explicitly, so a Vite plugin cannot
return `generateMap()`. Backport the upstream fix (rolldown/rolldown#10355,
released in 1.2.19) to the 1.1.5 that vite's `~1.1.5` range pins.

Fluent's ComponentState removes `null` from the always-rendered root slot.
With Slot now admitting `undefined`, the root needs the same exclusion so a
resolved root stays required.
The model, alias-rule, announced-metadata and pricing editors each patch an
object with `undefined` meaning "remove this optional field", and each one
spread the patch and then deleted the undefined keys by hand. Under
exactOptionalPropertyTypes a Partial<T> cannot carry that `undefined`.

FieldPatch<T> admits `undefined` only for optional fields, so clearing a
required field is a type error, and applyFieldPatch removes the cleared
keys. The editors now share it, and their stored values keep the same
shape.
Enable the web app under exactOptionalPropertyTypes.

- Our own component props declare optional props as `prop?: T | undefined`,
  the @types/react convention, so a caller can forward an absent value.
- Fluent non-slot props (validationState, sortDirection, onOptionSelect,
  onChange, intent, mountNode, positioning target, ...) are omitted at the
  call site when absent. A validationState that was `undefined` becomes
  `'none'`, which is what Fluent resolves it to whenever no message is shown.
- Loader signals reach the RPC client through abortOptions, and the catalog
  fetches take a required signal, since every caller has one.
- Account status, proxy issues, chart ranges, toaster options and the
  playground edit omit an absent field rather than carrying `undefined`.
- The dashboard's access resolution mirrors the gateway's: an eligible row
  carries its defined value, so ranking needs no assertion.
The alias and metadata editors now remove a cleared optional field and
write it back at the end when restored, where they used to leave the key in
place with an undefined value. A draft reverted to its opened values then
serialized with a different key order, and the discard guard compared raw
JSON strings, so Cancel asked to discard an unchanged draft. The guard now
compares canonical JSON, shared with the upstream editor's YAML check.
Hoisting the optional model fields into locals validated them before the
cross-field guards and before upstreamModelId, so a model with several
malformed fields reported a different first error than before. The locals
are now read after the guards, in the order the record lists them.
The Codex and Copilot regression tests compared values, which an explicit
undefined also satisfies. They now assert the keys are absent, and both fail
with the earlier fixes reverted. The fast-path sequence test pins the
expanded event list before checking that its numbering is contiguous.
@Menci
Menci merged commit 0221053 into main Nov 24, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant