Skip to content

fix(defaulted): skip factories when their defaults cannot be used - #1306

Open
FanWu-ai wants to merge 1 commit into
ianstormtaylor:mainfrom
FanWu-ai:fix-unused-default-factories-20261012
Open

FanWu-ai wants to merge 1 commit into
ianstormtaylor:mainfrom
FanWu-ai:fix-unused-default-factories-20261012

Conversation

@FanWu-ai

Copy link
Copy Markdown

The documented defaulted(number(), () => i++) ID generator advances even when an ID was supplied and its fallback is discarded. Creating {id: 42} followed by {} assigns the generated ID 1 rather than 0. A valid supplied value also throws when its unused default factory throws.

Return supplied values before evaluating fallbacks when strict mode is enabled or the input is not a plain object. Undefined input still evaluates once. Non-strict plain objects still evaluate the fallback because its properties may need merging. The wrapped struct's own coercer still executes.

Validation on Node 24.19.0 and 22.19.0:

  • Fresh complete baseline: 225 tests; final: 233, with full CJS/ESM build and both TypeScript projects passing.
  • Required configured lint/whole-project Prettier and supplemental direct changed-file ESLint pass.
  • Exact new tests on original source: 6 failures / 2 controls.
  • 4,028 independent assertions per runtime and 1,934 additional review cases pass, covering generated IDs, throwing factories, strict/object merging, non-plain/null-prototype values, result/reference parity and underlying trimming.

The reused dependencies retain an existing expect 29.7 compatibility resolution for wildcard @types/expect; no dependency change is made here, and a fresh unpinned CI install may differ. Other runtimes and hosted checks are not claimed passed. Prepared and tested with AI assistance (OpenAI Codex); no human review is claimed.

Avoid advancing generated IDs or invoking unused throwing factories for supplied non-object and strict values. Preserve undefined defaults, object merging and underlying coercion.

AI assistance: OpenAI Codex.
@FanWu-ai
FanWu-ai marked this pull request as ready for review October 11, 2026 22:35
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