feat(types): infer slots type from SetupContext in defineComponent#14688
feat(types): infer slots type from SetupContext in defineComponent#14688zhiyuanzmj wants to merge 8 commits intovuejs:mainfrom
Conversation
mergeProps Ensure event listeners that are explicitly null or undefined are preserved during prop merging instead of being dropped.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughBroadened slot-related type generics to accept either Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
Pull request overview
This PR updates runtime-core TypeScript typings to allow defineComponent / SetupContext slot typing to accept an “object slots” form (in addition to the existing SlotsType wrapper), and adds dts tests to cover the new inference path.
Changes:
- Expand slot-related generics to accept
SlotsType | SlotsacrossSetupContext,defineComponent, and public instance typing. - Add conditional logic intended to map object-slot inputs back into
SlotsTypefor$slotsinference. - Add dts tests asserting
$slots.defaultis not inferred asanywhen slots are provided viaSetupContext.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/runtime-core/src/componentPublicInstance.ts | Allows mixin public instance slot generic to accept Slots and conditionally wraps it. |
| packages/runtime-core/src/component.ts | Extends SetupContext slot generic and changes ctx.slots typing based on slot type form. |
| packages/runtime-core/src/apiDefineComponent.ts | Updates defineComponent overload generics/imports to accept Slots in addition to SlotsType. |
| packages-private/dts-test/defineComponent.test-d.tsx | Adds dts tests for slot inference flowing from SetupContext annotations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages-private/dts-test/defineComponent.test-d.tsx`:
- Around line 1178-1247: The tests reference the Vue type EmitsOptions but it
isn't imported; update the import list from 'vue' to include EmitsOptions so the
usages in the SetupContext generic parameters (seen in the Foo, Bar, and Qux
defineComponent blocks) resolve correctly; ensure the top-of-file import
alongside defineComponent, SetupContext, IsAny, etc., includes EmitsOptions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 486d3e1f-0113-474a-bc03-d0f5761d5da6
📒 Files selected for processing (4)
packages-private/dts-test/defineComponent.test-d.tsxpackages/runtime-core/src/apiDefineComponent.tspackages/runtime-core/src/component.tspackages/runtime-core/src/componentPublicInstance.ts
Just like a functional component.
Summary by CodeRabbit
New Features
Tests
Summary by CodeRabbit
New Features
Tests