-
Notifications
You must be signed in to change notification settings - Fork 544
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
fix(components): improve generic types #2499
base: v3
Are you sure you want to change the base?
Conversation
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Benjamin Canac <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Benjamin Canac <[email protected]>
commit: |
Thanks a lot for this! After some tests, I don't have autocomplete on custom slots for NavigationMenu, DropdownMenu, ContextMenu, etc. I think there's also the default slot missing for Accordion. (I've updated the PR to add the missing |
@@ -55,8 +56,52 @@ describe('Accordion', () => { | |||
['with body slot', { props: { ...props, modelValue: '1' }, slots: { body: () => 'Body slot' } }], | |||
['with custom slot', { props: { ...props, modelValue: '5' }, slots: { custom: () => 'Custom slot' } }], | |||
['with custom body slot', { props: { ...props, modelValue: '5' }, slots: { 'custom-body': () => 'Custom body slot' } }] | |||
])('renders %s correctly', async (nameOrHtml: string, options: { props?: AccordionProps<typeof items[number]>, slots?: Partial<AccordionSlots<typeof items[number]>> }) => { | |||
])('renders %s correctly', async (nameOrHtml: string, options: { props?: AccordionProps<typeof items>, slots?: Partial<AccordionSlots<typeof items>> }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this change not applied everywhere? 🤔
src/runtime/components/Accordion.vue
Outdated
body: SlotProps<T> | ||
} & DynamicSlots<T, SlotProps<T>> | ||
export type AccordionSlots<Items> = | ||
(DynamicSlots<Items, null, 'trailing' | 'leading' | 'body' | 'content'> extends infer S ? { [K in keyof S]: SlotProps<S[K]> } & Record<string, any> : never) & (DynamicSlots<Items, 'body', null> extends infer S ? { [K in keyof S]: SlotProps<S[K]> } & Record<string, any> : never) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there two definition for body
? 🤔
I thought you were talking about slot name autocomplete. To know how you can define items, I'd just do Is this PR ready to merge? |
Yes I was talking about the slot name autocomplete, how can you have it without specifying that it's a constant? Anyway, I was just going through the PR and actually I think i overly complicated things, let me have another go at it 😅 sorry for the going back and forth |
@yassilah Should I close this? Do you plan to start over or improve this PR? |
🔗 Linked issue
Replaces #2490, #2491, #2482
Resolves #2260, resolves #2140
This PR is a full refactor of dynamic slots inside components with improved generic types, dynamic slot names, custom properties, arrays of arrays, etc. It includes type tests for all of the components to check the payload of each slot and infer available slot names based on props.
It also replaces the previous
DynamicSlots
type helper with a new one:❓ Type of change
📚 Description
📝 Checklist