-
-
Notifications
You must be signed in to change notification settings - Fork 9k
feat(types): Add Exposed template to SetupContext #13177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(types): Add Exposed template to SetupContext #13177
Conversation
Size ReportBundles
Usages
|
@vue/compiler-core
npm i https://pkg.pr.new/@vue/compiler-core@13177
@vue/compiler-dom
npm i https://pkg.pr.new/@vue/compiler-dom@13177
@vue/compiler-sfc
npm i https://pkg.pr.new/@vue/compiler-sfc@13177
@vue/compiler-ssr
npm i https://pkg.pr.new/@vue/compiler-ssr@13177
@vue/reactivity
npm i https://pkg.pr.new/@vue/reactivity@13177
@vue/runtime-core
npm i https://pkg.pr.new/@vue/runtime-core@13177
@vue/runtime-dom
npm i https://pkg.pr.new/@vue/runtime-dom@13177
@vue/server-renderer
npm i https://pkg.pr.new/@vue/server-renderer@13177
@vue/shared
npm i https://pkg.pr.new/@vue/shared@13177
vue
npm i https://pkg.pr.new/vue@13177
@vue/compat
npm i https://pkg.pr.new/@vue/compat@13177
commit: bd8c78d
jh-leong
commented
Apr 9, 2025
Thanks for the PR!
Could you please add test cases for this change in:
packages-private/dts-test/defineComponent.test-d.tsxpackages-private/dts-test/functionalComponent.test-d.tsx
This would help verify the type behavior.
michaelcozzolino
commented
Apr 12, 2025
Thanks for the PR!
Could you please add test cases for this change in:
packages-private/dts-test/defineComponent.test-d.tsxpackages-private/dts-test/functionalComponent.test-d.tsxThis would help verify the type behavior.
I added a test, but i was able to achieve the goal just partially, the expose keys seem to be typed properly, but the values are not typed at all, do you have any suggestions?
edison1105
commented
Apr 17, 2025
@michaelcozzolino
Could you please fix the test failing?
WalkthroughThe changes introduce enhanced type safety and explicit typing for component property exposure in a component-based framework. New generic parameters are added to core types and function overloads to allow precise specification of which properties are exposed to component instances, both in options objects and setup functions. The test suite is expanded to verify that only explicitly exposed properties are accessible on component instances and that typings reflect these constraints. These adjustments impact type declarations for component definitions, setup contexts, and functional components, supporting stricter and more expressive public API contracts. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Component
participant SetupFunction
participant Instance
User->>Component: defineComponent({ setup(ctx) { ctx.expose({a, b}) } })
Component->>SetupFunction: Call setup with SetupContext (expose method)
SetupFunction->>SetupFunction: Call ctx.expose({a, b})
SetupFunction-->>Component: Return setup result
Component->>Instance: Create instance with exposed properties a, b
User->>Instance: Access instance.a / instance.b (allowed)
User->>Instance: Access instance.c (TypeScript error)
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code Graph Analysis (2)packages-private/dts-test/defineComponent.test-d.tsx (3)
packages/runtime-core/src/apiDefineComponent.ts (5)
🪛 Biome (1.9.4)packages-private/dts-test/defineComponent.test-d.tsx[error] 1643-1643: Don't use 'String' as a type. Use lowercase primitives for consistency. (lint/complexity/noBannedTypes) packages/runtime-core/src/apiDefineComponent.ts[error] 138-138: Don't use '{}' as a type. Prefer explicitly define the object shape. '{}' means "any non-nullable value". (lint/complexity/noBannedTypes) [error] 139-139: Don't use '{}' as a type. Prefer explicitly define the object shape. '{}' means "any non-nullable value". (lint/complexity/noBannedTypes) [error] 180-180: Don't use '{}' as a type. Prefer explicitly define the object shape. '{}' means "any non-nullable value". (lint/complexity/noBannedTypes) [error] 182-182: Don't use '{}' as a type. Prefer explicitly define the object shape. '{}' means "any non-nullable value". (lint/complexity/noBannedTypes) 🔇 Additional comments (10)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Uh oh!
There was an error while loading. Please reload this page.
This PR allows the possibility to type
exposewhen usingdefineComponentwith composition apiI added the template wherever it would be needed.
i'm not sure if in
packages/runtime-core/src/componentOptions.tsat line 142 it's needed as well, as i already see anExposedtemplate, but doesn't look like having the type for the one inSetupContext. let me know if everything is fineSummary by CodeRabbit