Skip to content

Conversation

@serkodev
Copy link
Contributor

@serkodev serkodev commented Nov 19, 2025

Fixed: #14117
Fixed: vuejs/language-tools#5069

Summary by CodeRabbit

  • Type System Changes

    • Updated component expose API typing to strictly use string type, affecting how exposed properties are type-checked in TypeScript.
  • Tests

    • Added new test coverage for component definition with various configuration options.

@coderabbitai
Copy link

coderabbitai bot commented Nov 19, 2025

Walkthrough

Changes modify TypeScript type definitions in the Options API component setup to fix a typing regression where using the expose option prevented access to this properties (data, props, methods, computed) in other component options.

Changes

Cohort / File(s) Summary
Test Addition
packages-private/dts-test/defineComponent.test-d.tsx
Adds new test block for issue #14117 exercising defineComponent with setup, data, props, methods, computed, and expose APIs
Type Definition Fixes
packages/runtime-core/src/apiDefineComponent.ts
Replaces Exposed type parameter with string in CreateComponentPublicInstanceWithMixins generic argument within DefineComponent type
Component Options Types
packages/runtime-core/src/componentOptions.ts
Replaces Exposed generic parameter with string in CreateComponentPublicInstanceWithMixins calls across ComponentOptionsWithoutProps, ComponentOptionsWithArrayProps, and ComponentOptionsWithObjectProps public type signatures

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Changes are straightforward type parameter replacements across three files
  • Homogeneous pattern (same modification repeated consistently)
  • Limited scope with focused intent
  • Primary review focus: verify that constraining Exposed to string resolves the typing issue without introducing regressions in existing component definitions

Suggested labels

p3-minor-bug

Poem

🐰 When expose breaks the Options way,
And this won't play with data's say,
A string constraint saves the day,
Now setup, methods, computed stay—
Type safety hops back into play! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing Options API typing issues when expose is used in defineComponent.
Linked Issues check ✅ Passed The PR addresses the core issue #14117 by modifying type definitions to preserve this context access to props, setup, data, and methods when expose is defined.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the expose typing issue: test addition validates the fix, and type parameter changes in apiDefineComponent and componentOptions restore proper typing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@github-actions
Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 103 kB 38.9 kB 35.1 kB
vue.global.prod.js 161 kB 58.8 kB 52.4 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.9 kB 18.3 kB 16.8 kB
createApp 55 kB 21.4 kB 19.6 kB
createSSRApp 59.3 kB 23.1 kB 21.1 kB
defineCustomElement 60.6 kB 23.1 kB 21.1 kB
overall 69.3 kB 26.6 kB 24.3 kB

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 19, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@14118

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@14118

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@14118

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@14118

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@14118

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@14118

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@14118

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@14118

@vue/shared

npm i https://pkg.pr.new/@vue/shared@14118

vue

npm i https://pkg.pr.new/vue@14118

@vue/compat

npm i https://pkg.pr.new/@vue/compat@14118

commit: cba4209

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages-private/dts-test/defineComponent.test-d.tsx (1)

2111-2144: New #14117 dts test repros the regression clearly

This defineComponent block is a good minimal dts-level repro: computed1 touches setup bindings (both exposed and non-exposed), data, props, and methods while expose: ['setup1'] is present, so any future regression that narrows this to the expose keys will break compilation here. If you want even stronger guarantees, you could optionally add expectType assertions on this.setup1, this.setup2, etc., but the current form is already effective.

Please ensure this file is included in the dts test run used in CI so this scenario remains covered.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83f6ab6 and cba4209.

📒 Files selected for processing (3)
  • packages-private/dts-test/defineComponent.test-d.tsx (1 hunks)
  • packages/runtime-core/src/apiDefineComponent.ts (1 hunks)
  • packages/runtime-core/src/componentOptions.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages-private/dts-test/defineComponent.test-d.tsx (1)
packages/runtime-core/src/apiDefineComponent.ts (1)
  • defineComponent (305-315)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test / e2e-test
  • GitHub Check: test / unit-test-windows
🔇 Additional comments (2)
packages/runtime-core/src/apiDefineComponent.ts (1)

258-277: Decoupling Options API this from expose looks correct and localized

Routing the CreateComponentPublicInstanceWithMixins Exposed parameter to string in the ThisType<...> for the options-object overload ensures that expose no longer shrinks the this type inside options (data/computed/methods/etc.), while the returned DefineComponent still threads the real Exposed through to the public instance type. This is the right place to fix #14117 and should not affect external instance typings or the existing expose tests, since only the internal options this context is relaxed here.

Please confirm the dts suite / vue-tsc fixtures still pass (packages-private/dts-test) so we’re sure no other call sites relied on the previous tighter Exposed wiring for ThisType.

packages/runtime-core/src/componentOptions.ts (1)

1181-1199: Aligning legacy ComponentOptions ThisType with the expose fix is appropriate*

Passing a plain string as the Exposed parameter to CreateComponentPublicInstanceWithMixins in these deprecated ComponentOptionsWithoutProps / ComponentOptionsWithArrayProps aliases makes their this-context behavior consistent with the defineComponent overload fix: expose continues to control the public instance surface but no longer restricts the options this type. This improves ergonomics for users still on these aliases and should not affect existing “expose typing” tests, since the public instance type still carries the real Exposed union.

Please re-run the dts tests that exercise the legacy ComponentOptions* exports to confirm there are no unexpected downstream type changes.

Also applies to: 1243-1261

@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Nov 20, 2025

📝 Ran ecosystem CI: Open

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

@edison1105 edison1105 merged commit 8f82f23 into vuejs:main Nov 20, 2025
14 checks passed
@serkodev serkodev deleted the fix/define-component-expose-dts branch November 20, 2025 16:49
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.

defineComponent: exposing properties breaks Options API typings Using expose in options API breaks vue-tsc typing in templates in Vue 3.5

5 participants