Repository navigation
chore: enable exactOptionalPropertyTypes across the repository - #765
Merged
Merged
Conversation
@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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Optional properties across the repository were typed as
prop?: T, which TypeScript treats asT | undefinedunlessexactOptionalPropertyTypesis 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.jsonenablesexactOptionalPropertyTypesfor every project. Each package states an absent value by omitting the key, and a type admitsundefinedonly where the value genuinely passes through it:toRequestInit, signal and option bags admitundefinedexplicitly, and about 250 control-plane zod fields use.exactOptional(), so a parsed body carries only the keys a client sent. The dumplimitis parsed withz.preprocess, and the flag-override schema rejects an explicitundefined(.exactOptional() paired with coercion produces unexpected values colinhacks/zod#6236).prop?: T | undefined, the@types/reactconvention. Fluent non-slot props are omitted when absent. AvalidationStatethat wasundefinedis now'none', which Fluent resolves it to whenever no message is shown. The model, alias-rule, announced-metadata, and pricing editors shareFieldPatch<T>:undefinedclears 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 explicitundefinedused 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:max_context_windowwhen the upstream states none.Dependency declarations that reject values their own sources produce are patched and documented in
pnpm-workspace.yaml:@fluentui/react-utilitiesundefined.Slotadmitsundefined, andComponentStatekeepsrootrequired.honoJSONParsedkeeping optional properties optional@hono/node-serverwsstub admits theundefinedthat@types/wsdeclaresrolldownExistingRawSourceMapadmittingundefined. Vite pins~1.1.5.Verification
tsc --noEmitpasses in all 23 TypeScript projects,apps/webincluded.pnpm run build:webpasses.checked/defaultCheckedwarning also appears onmain.