feat(types): support JSX children typing for defineComponent#14710
feat(types): support JSX children typing for defineComponent#14710zhiyuanzmj wants to merge 6 commits intovuejs:mainfrom
Conversation
Add ResolveComponentProps and JSXElementChildrenAttribute types. Expose ElementChildrenAttribute in JSX runtime and global JSX types. Wire the new props resolution into defineComponent and add dts tests.
|
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 (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughUpdates TypeScript JSX/slot typings: introduces Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
🧹 Nitpick comments (1)
packages/runtime-core/src/componentProps.ts (1)
42-43: Consider using relative imports instead of self-referential package import.Importing from
@vue/runtime-corewithinpackages/runtime-core/src/componentProps.tsis a self-referential import. This can cause issues with circular dependencies or build order. The typesEmitsToProps,SlotsType, andVNodeChildare all defined within this package and should use relative imports for consistency with the rest of the codebase.♻️ Suggested fix
-import type { EmitsToProps, SlotsType, VNodeChild } from '@vue/runtime-core' +import type { EmitsToProps } from './componentEmits' +import type { SlotsType } from './componentSlots' +import type { VNodeChild } from './vnode'#!/bin/bash # Check how other files in runtime-core import these types echo "=== Checking EmitsToProps imports ===" rg -n "import.*EmitsToProps" packages/runtime-core/src/ --type ts echo -e "\n=== Checking SlotsType imports ===" rg -n "import.*SlotsType" packages/runtime-core/src/ --type ts echo -e "\n=== Checking VNodeChild imports ===" rg -n "import.*VNodeChild" packages/runtime-core/src/ --type ts🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime-core/src/componentProps.ts` around lines 42 - 43, Replace the self-referential external import of the types EmitsToProps, SlotsType, and VNodeChild with a relative import from the local runtime-core package and keep UnwrapSlotsType consistent; locate the import statement that currently reads import type { EmitsToProps, SlotsType, VNodeChild } from '@vue/runtime-core' and change it to import those same type names via a relative module within the package (matching how UnwrapSlotsType is imported) so the file no longer depends on the package public entry and avoids circular/build-order issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/runtime-core/src/componentProps.ts`:
- Around line 42-43: Replace the self-referential external import of the types
EmitsToProps, SlotsType, and VNodeChild with a relative import from the local
runtime-core package and keep UnwrapSlotsType consistent; locate the import
statement that currently reads import type { EmitsToProps, SlotsType, VNodeChild
} from '@vue/runtime-core' and change it to import those same type names via a
relative module within the package (matching how UnwrapSlotsType is imported) so
the file no longer depends on the package public entry and avoids
circular/build-order issues.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4a8db233-80ea-45c9-9b09-214ab9628240
📒 Files selected for processing (7)
packages-private/dts-test/defineComponent.test-d.tsxpackages-private/dts-test/utils.d.tspackages/runtime-core/src/apiDefineComponent.tspackages/runtime-core/src/componentProps.tspackages/runtime-core/src/index.tspackages/vue/jsx-runtime/index.d.tspackages/vue/jsx.d.ts
There was a problem hiding this comment.
Pull request overview
This PR adds opt-in TypeScript support for JSX “children” (slots) type checking in defineComponent by allowing projects to declare which prop name should be treated as the JSX children attribute (e.g. 'v-slots').
Changes:
- Introduces
JSXElementChildrenAttributeand wiresdefineComponentprops typing through a newResolveComponentPropshelper type so TSX children can be type-checked against declared slots. - Extends the Vue JSX typings (
vue/jsxandvue/jsx-runtime) to hook into TypeScript’sElementChildrenAttributemechanism. - Updates dts tests to enable the feature via module augmentation and adds TSX usage examples for slot children.
Reviewed changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/vue/jsx.d.ts | Adds ElementChildrenAttribute wiring for global JSX children typing. |
| packages/vue/jsx-runtime/index.d.ts | Adds ElementChildrenAttribute wiring for @jsxImportSource runtime. |
| packages/runtime-core/src/index.ts | Re-exports the new types from runtime-core’s public type surface. |
| packages/runtime-core/src/componentProps.ts | Defines JSXElementChildrenAttribute and ResolveComponentProps used by defineComponent typing. |
| packages/runtime-core/src/apiDefineComponent.ts | Switches defineComponent prop resolution to use ResolveComponentProps. |
| packages-private/dts-test/utils.d.ts | Enables the new behavior for the dts test suite via declare module 'vue' augmentation. |
| packages-private/dts-test/defineComponent.test-d.tsx | Adds TSX usage examples for typed slot children and updates component identifiers for JSX. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
Setup
Defines which prop name is used for JSX children (slots) type checking.
This is not set by default. To enable it, add the following declaration in your vue-jsx project:
Usage
Summary by CodeRabbit
Tests
Refactor