Skip to content

fix: attach fn, arrayFn, extend to defu function to match its type#174

Open
Mohammad-Faiz-Cloud-Engineer wants to merge 1 commit into
unjs:mainfrom
Mohammad-Faiz-Cloud-Engineer:main
Open

fix: attach fn, arrayFn, extend to defu function to match its type#174
Mohammad-Faiz-Cloud-Engineer wants to merge 1 commit into
unjs:mainfrom
Mohammad-Faiz-Cloud-Engineer:main

Conversation

@Mohammad-Faiz-Cloud-Engineer

@Mohammad-Faiz-Cloud-Engineer Mohammad-Faiz-Cloud-Engineer commented May 31, 2026

Copy link
Copy Markdown

DefuInstance interface declares these properties but defu = createDefu() just returns a bare function, the as DefuInstance cast was lying to TypeScript. Anyone calling defu.fn(), defu.arrayFn(), or defu.extend() would get a runtime crash despite passing typecheck.

Reordered defuFn/defuArrayFn before defu so they can be referenced, then used Object.assign to attach them to the function object. CJS bridge (lib/defu.cjs) auto-picks these up via module.exports = defu.

Summary by CodeRabbit

  • New Features
    • Extended the main export with additional utility functions and helper properties for enhanced flexibility and functionality.

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 617d3213-911d-4977-bceb-84c8581dff34

📥 Commits

Reviewing files that changed from the base of the PR and between 82632b6 and 17bc4e9.

📒 Files selected for processing (1)
  • src/defu.ts

📝 Walkthrough

Walkthrough

The PR updates the main defu export to include convenience properties—fn, arrayFn, and extend—by wrapping createDefu() with Object.assign. The default export is updated accordingly, maintaining backward compatibility while exposing internal merger functions and the extend capability directly on the instance.

Changes

Defu Instance Export Enrichment

Layer / File(s) Summary
Enrich defu export with convenience properties
src/defu.ts
The standard defu export is replaced with Object.assign(createDefu(), { fn: defuFn, arrayFn: defuArrayFn, extend: createDefu }), attaching convenience properties to the main instance; the default export now references this enriched shape.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • unjs/defu#157: Both PRs adjust the public defu export shape—this PR changes the runtime defu instance to include fn/arrayFn/extend, while the related PR updates the corresponding .d.cts typing to match that enriched structure.

Suggested reviewers

  • pi0

Poem

🐰 A rabbit's refrain on enrichment so true:
The defu default grew properties new,
With fn, arrayFn, and extend in sight,
The shape is more full, yet backward stays tight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: attach fn, arrayFn, extend to defu function to match its type' clearly and specifically describes the main change: attaching missing properties to the defu function to align runtime behavior with its TypeScript type definition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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