Skip to content

feat(types): support JSX children typing for defineComponent#14710

Open
zhiyuanzmj wants to merge 6 commits intovuejs:mainfrom
zhiyuanzmj:jsx-slots
Open

feat(types): support JSX children typing for defineComponent#14710
zhiyuanzmj wants to merge 6 commits intovuejs:mainfrom
zhiyuanzmj:jsx-slots

Conversation

@zhiyuanzmj
Copy link
Copy Markdown
Member

@zhiyuanzmj zhiyuanzmj commented Apr 12, 2026

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:

declare module 'vue' {
  interface JSXElementChildrenAttribute {
     'v-slots': {}
  }
}

Usage

const Comp = defineComponent(
  <T,>(
     props: { foo: T },
     { slots }: {
       slots: {
         default?: (props: { foo: T }) => any
       }
     },
   ) => slots.default?.(props),
 )
 
;<Comp foo={1}>{({ foo }) => [foo === 1]}</Comp>

Summary by CodeRabbit

  • Tests

    • Expanded TypeScript tests to cover more JSX/TSX slot usage and props inference cases.
  • Refactor

    • Enhanced typing so component props now incorporate slot-derived types.
    • Added explicit JSX children attribute typing and re-exported types to improve TypeScript inference for JSX/TSX slots.

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.
Copilot AI review requested due to automatic review settings April 12, 2026 17:21
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f831628-8472-4c22-9383-87a1282db26b

📥 Commits

Reviewing files that changed from the base of the PR and between b6825a6 and 005c5dd.

📒 Files selected for processing (3)
  • packages/runtime-core/src/apiDefineComponent.ts
  • packages/runtime-core/src/componentProps.ts
  • packages/runtime-core/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/runtime-core/src/index.ts
  • packages/runtime-core/src/apiDefineComponent.ts

📝 Walkthrough

Walkthrough

Updates TypeScript JSX/slot typings: introduces JSXElementChildrenAttribute and SlotsToProps, wires slot-derived props into defineComponent types, re-exports new types, updates JSX runtime declarations, and adds test adjustments and a module augmentation for v-slots.

Changes

Cohort / File(s) Summary
DefineComponent & props types
packages/runtime-core/src/apiDefineComponent.ts, packages/runtime-core/src/componentProps.ts
Add JSXElementChildrenAttribute and SlotsToProps; incorporate slot-derived props into DefineComponent and DefineSetupFnComponent type signatures.
Public exports
packages/runtime-core/src/index.ts
Re-export JSXElementChildrenAttribute and SlotsToProps from componentProps.
JSX declarations
packages/vue/jsx-runtime/index.d.ts, packages/vue/jsx.d.ts
Add JSX.ElementChildrenAttribute that extends JSXElementChildrenAttribute to surface JSX children attribute typing.
Tests & test utils
packages-private/dts-test/defineComponent.test-d.tsx, packages-private/dts-test/utils.d.ts
Rename test components (comp1Comp1, comp2Comp2), add TSX slot usage assertions (including fragment/object slot forms), and add module augmentation declaring v-slots in vue's JSXElementChildrenAttribute.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ready for review

Suggested reviewers

  • jh-leong

Poem

🐰 I hopped through types and stitched some slots,
Folded JSX paths into tiny knots.
Props and children now hum in tune,
Tests cheer softly under the moon.
A tiny hop — and types are hot.

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(types): support JSX children typing for defineComponent' accurately describes the main change: adding TypeScript support for typing JSX children/slots in defineComponent.

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

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

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

@github-actions
Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 105 kB 39.9 kB 35.8 kB
vue.global.prod.js 164 kB 59.9 kB 53.2 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.3 kB 18.8 kB 17.2 kB
createApp 56.5 kB 21.8 kB 20 kB
createSSRApp 60.7 kB 23.6 kB 21.5 kB
defineCustomElement 62.6 kB 23.8 kB 21.7 kB
overall 71 kB 27.2 kB 24.7 kB

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 12, 2026

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14710
npm i https://pkg.pr.new/@vue/compiler-core@14710
yarn add https://pkg.pr.new/@vue/compiler-core@14710.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14710
npm i https://pkg.pr.new/@vue/compiler-dom@14710
yarn add https://pkg.pr.new/@vue/compiler-dom@14710.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14710
npm i https://pkg.pr.new/@vue/compiler-sfc@14710
yarn add https://pkg.pr.new/@vue/compiler-sfc@14710.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14710
npm i https://pkg.pr.new/@vue/compiler-ssr@14710
yarn add https://pkg.pr.new/@vue/compiler-ssr@14710.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14710
npm i https://pkg.pr.new/@vue/reactivity@14710
yarn add https://pkg.pr.new/@vue/reactivity@14710.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14710
npm i https://pkg.pr.new/@vue/runtime-core@14710
yarn add https://pkg.pr.new/@vue/runtime-core@14710.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14710
npm i https://pkg.pr.new/@vue/runtime-dom@14710
yarn add https://pkg.pr.new/@vue/runtime-dom@14710.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14710
npm i https://pkg.pr.new/@vue/server-renderer@14710
yarn add https://pkg.pr.new/@vue/server-renderer@14710.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14710
npm i https://pkg.pr.new/@vue/shared@14710
yarn add https://pkg.pr.new/@vue/shared@14710.tgz

vue

pnpm add https://pkg.pr.new/vue@14710
npm i https://pkg.pr.new/vue@14710
yarn add https://pkg.pr.new/vue@14710.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14710
npm i https://pkg.pr.new/@vue/compat@14710
yarn add https://pkg.pr.new/@vue/compat@14710.tgz

commit: 005c5dd

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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-core within packages/runtime-core/src/componentProps.ts is a self-referential import. This can cause issues with circular dependencies or build order. The types EmitsToProps, SlotsType, and VNodeChild are 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7df0edd and ba7a95a.

📒 Files selected for processing (7)
  • packages-private/dts-test/defineComponent.test-d.tsx
  • packages-private/dts-test/utils.d.ts
  • packages/runtime-core/src/apiDefineComponent.ts
  • packages/runtime-core/src/componentProps.ts
  • packages/runtime-core/src/index.ts
  • packages/vue/jsx-runtime/index.d.ts
  • packages/vue/jsx.d.ts

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 JSXElementChildrenAttribute and wires defineComponent props typing through a new ResolveComponentProps helper type so TSX children can be type-checked against declared slots.
  • Extends the Vue JSX typings (vue/jsx and vue/jsx-runtime) to hook into TypeScript’s ElementChildrenAttribute mechanism.
  • 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.

@zhiyuanzmj
Copy link
Copy Markdown
Member Author

/ecosystem-ci run

@vue-bot
Copy link
Copy Markdown
Contributor

vue-bot commented Apr 12, 2026

📝 Ran ecosystem CI: Open

suite result latest scheduled
pinia success success
quasar success success
primevue success success
language-tools failure failure
router success success
vueuse success success
vuetify success success
radix-vue success success
vue-i18n success success
vant success success
vitepress success success
vue-macros success success
vue-simple-compiler success success
test-utils success success
nuxt success success
vite-plugin-vue success success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants