-
Notifications
You must be signed in to change notification settings - Fork 616
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
[Table] Generic component #818
Comments
If I understand correctly, this would type the <UTable :rows="items" :columns="columns">
<template #quantity-data="{ row }">
{{ row.quantity.value }}
</template>
</UTable> |
I thinl you understand well @benjamincanac and I would also be super interested by that thing! 🥇 |
I meant when using the component directly, with support for generic through vuejs/rfcs#436. |
What do you mean by using the component directly? Why would you care to type the |
Generic row will means that we can enforce type, eg: |
Honestly, I'm not really sure how to implement this if you have any clue! |
What's the reason you didn't use the function signature or the script setup syntax for components? https://vuejs.org/api/general#function-signature typing generic components is not possible (?) without using the function signature |
For now, you can do something like this <UTable :rows="people">
<template #name-data="{ row }: { row: typeof people[number] }">
<p>{{ row }}</p>
</template>
</UTable> |
@metkm When open-sourcing this library with the whole App Config theming system, I had to rewrite everything with |
Script setup syntax now supports default props: https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits If we are OK w/ converting the component to use Outside of the default props requirement, are there any other concerns that need to be kept in mind for such a conversion? My only thought is that it seems desirable to use a consistent declaration syntax across all components defined in the library which could be an argument against such a change, but implementing generics could be a powerful feature for more components than just the table. Thoughts? |
I guess we can consider this for |
@zoobzio Also, when using |
Does it work with this syntax? withDefaults(
defineProps<{
test: string
}>(),
{
test: config
}
) |
Won't work either: https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits
Also not recommended to use type-based declaration for a module like this, it adds an extra compilation step to transform it to the same code you'd wrote using runtime declaration. By the way there is an awesome video from @danielroe about this: https://www.youtube.com/watch?v=fA0ezJCGMuA |
I opened a PR that implements a working example of how generics might look in the library, just migrating to I also played around w/ typing the column key like To solve the problem of local vars not playing nice w/ import { defu } from 'defu'
import { config } from '#ui/ui.config'
const props = defineProps({
ui: {
type: Object,
default: undefined
})
const { ui } = defu(props, config.default) @benjamincanac |
Closing in favor of #2139. |
Description
Add generic to components such as
UTable
so that user can have better type control.Additional context
UTable
is a component that I use very often, and I usually find myself missing some properties of some rows. I think adding generics to suck components will help enhance the DX a lots.The text was updated successfully, but these errors were encountered: