-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
base: main
Are you sure you want to change the base?
feat(types): Add Exposed template to SetupContext #13177
Conversation
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: |
Thanks for the PR! Could you please add test cases for this change in:
This 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? |
@michaelcozzolino |
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 (
|
This PR allows the possibility to type
expose
when usingdefineComponent
with composition apiI added the template wherever it would be needed.
i'm not sure if in
packages/runtime-core/src/componentOptions.ts
at line 142 it's needed as well, as i already see anExposed
template, but doesn't look like having the type for the one inSetupContext
. let me know if everything is fineSummary by CodeRabbit