Skip to content

fix: improve UnwrapRefs type to handle optional Ref types#102

Merged
wangshunnn merged 1 commit into
mainfrom
fix-toRefs
Mar 2, 2026
Merged

fix: improve UnwrapRefs type to handle optional Ref types#102
wangshunnn merged 1 commit into
mainfrom
fix-toRefs

Conversation

@wangshunnn

@wangshunnn wangshunnn commented Mar 2, 2026

Copy link
Copy Markdown
Collaborator

closes #101

Summary by CodeRabbit

  • New Features

    • Added example component demonstrating reactive reference handling for nested properties with optional chaining support.
  • Improvements

    • Enhanced type system to better handle reactive references that may be undefined, improving type inference accuracy.

Handle cases where T[K] extends Ref<infer V> | undefined, properly
unwrapping optional refs in the UnwrapRefs type definition.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c67623 and 3474ecb.

📒 Files selected for processing (2)
  • inspect-extension/components/composition/toRefs.mpx
  • packages/language-core/src/codegen/globalTypes/index.ts

📝 Walkthrough

Walkthrough

A new MPX component is added that demonstrates toRefs usage with nested optional properties. The type system is updated to correctly handle Ref<infer V> | undefined in the UnwrapRefs type definition, ensuring proper type unwrapping when refs may be undefined.

Changes

Cohort / File(s) Summary
New toRefs Example Component
inspect-extension/components/composition/toRefs.mpx
Demonstrates toRefs applied to a nested prop structure with optional chaining, exposing the ref via defineExpose for external access.
Type System Update
packages/language-core/src/codegen/globalTypes/index.ts
Enhanced UnwrapRefs type to handle Ref types that may be undefined, adding conditional branch to properly unwrap V from Ref | undefined patterns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A ref that might be undefined,
Now unwraps with types refined,
toRefs brings nested props to light,
Templates render TypeScript right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: improving the UnwrapRefs type to handle optional Ref types, which directly addresses the issue of toRefs type handling.
Linked Issues check ✅ Passed The PR updates UnwrapRefs type to handle optional Ref types (Ref | undefined) and adds a test component demonstrating toRefs usage with nested props, directly addressing the TypeScript type issue (#101).
Out of Scope Changes check ✅ Passed All changes are within scope: the UnwrapRefs type fix directly resolves #101, and the test component demonstrates the fix with toRefs and nested optional properties.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-toRefs

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@wangshunnn wangshunnn merged commit 0c1b154 into main Mar 2, 2026
2 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.

【TS】toRefs 拿到的变量,在模板上不能拿到正确的类型

1 participant