Repository navigation
fix: support exactOptionalPropertyTypes and narrow duplex type - #87
Closed
YevheniiKotyrlo wants to merge 1 commit into
Closed
YevheniiKotyrlo wants to merge 1 commit into
YevheniiKotyrlo wants to merge 1 commit into
Conversation
YevheniiKotyrlo
force-pushed
the
fix/exact-optional-property-types
branch
from
February 25, 2026 15:28
82b0ab7 to
dbc1a0a
Compare
YevheniiKotyrlo
force-pushed
the
fix/exact-optional-property-types
branch
from
February 25, 2026 15:41
dbc1a0a to
7a7e597
Compare
Enable exactOptionalPropertyTypes in tsconfig so emitted .d.ts files don't expand optional properties with | undefined. Fix two code patterns in create-fetch that assign possibly-undefined values to optional properties. Narrow duplex from "full" | "half" to "half" per WHATWG Fetch spec.
YevheniiKotyrlo
force-pushed
the
fix/exact-optional-property-types
branch
from
February 25, 2026 15:44
7a7e597 to
c444890
Compare
|
Thank you @YevheniiKotyrlo , this fix works for me! Just FYI, the current main at a9ec141 also appears to fix the two compile errors. |
bytaesu
reviewed
Sep 4, 2026
| * Duplex mode | ||
| */ | ||
| duplex?: "full" | "half"; | ||
| duplex?: "half"; |
Collaborator
There was a problem hiding this comment.
I'll fix this on next minor release (not patch)
Collaborator
|
Hi @YevheniiKotyrlo, I cherry-picked your commitss, and this issue will be fixed in PR #133 |
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.
Summary
exactOptionalPropertyTypes: truein tsconfig so emitted.d.tsfiles don't expand optional properties with| undefinedcreate-fetch/index.tsthat assign possibly-undefined values to optional propertiesduplextype from"full" | "half"to"half"per WHATWG Fetch specCloses #86
Problem
The
Prettify<T>mapped type causes tsup to emit| undefinedon all optional properties in the inline-expanded generic default, while the constraint stays as an alias reference. WithexactOptionalPropertyTypes: true, the expanded default doesn't satisfy its own constraint, producing TS2344 onbetterFetch.Changes
1.
tsconfig.json— enable flag"strict": true, +"exactOptionalPropertyTypes": true,2.
src/create-fetch/index.ts— conditional spreadsWith
exactOptionalPropertyTypes, assigningundefinedto an optional property is an error. Four places need conditional spread:let opts = { ...options, - method: keySchema.method, - output: keySchema.output, - headers: validatedHeaders, + ...(keySchema.method != null ? { method: keySchema.method } : undefined), + ...(keySchema.output != null ? { output: keySchema.output } : undefined), + ...(validatedHeaders != null ? { headers: validatedHeaders } : undefined), };return { url, - options, + ...(options != null ? { options } : undefined), };3.
src/types.ts— narrow duplexThe WHATWG Fetch spec IDL enum only defines
"half". Full-duplex was discussed but never standardized.Verification
Verified on v1.1.21 (current npm release, which builds cleanly):
tsc --noEmitpnpm build(tsup)| undefinedin BetterFetchOption)exactOptionalPropertyTypes+skipLibCheck: false)Timertype leak remains)Note on CI
CI will fail due to a pre-existing build breakage on
main— undefinedheadersvariable inutils.ts(introduced in #65, tracked in #85, fix in #81). This PR does not touchutils.ts.