-
-
Notifications
You must be signed in to change notification settings - Fork 143
BTable typing of slot parameters #1305
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
Comments
The typing didn't change in the library. What did change was Vue 3.3. In Vue 3.3 defineSlots was introduced. I'm suspecting the default transitioned from "any" to "unknown". Plans to use generics are underway |
i'm not sure about that if i'm honest. |
And during that period we updated to Vue 3.3 |
Could it help? |
in theory yes - but it'd assume that the component is defined as generic component - which BTable currently isn't (
|
I'm in the same situation.. I can't imagine to 'cast' every single item in table slots... I think dynamic slots in table row should be defined with defineSlots in some way... something like that (IT DOESN'T WORK it's simply an idea): defineSlots<{
[K in keyof TableItem as K extends string ? `cell(${K})` : never]?: (_: {
item: TableItem[K]
}) => any
}>() in your example const tableItems: TableItem<ComparisonItem> = [
...
] should be const tableItems: TableItem<ComparisonItem>[] = [
...
] but then BTable items prop has a VS code warning that it isn't a TableItem[] type.... |
I think @VividLemon is working on generics #1316 https://dev.to/vincentdorian/vue-33-generic-types-and-when-to-use-them-5egn |
@VividLemon are you working on that? Can I help you? |
Though generics are possible with 3.3, they are in a buggy state which makes them near impossible to use. |
I understand... What do you suggest in the meantime? vue-sfc fails to build |
@VividLemon have a look at https://github.com/Shyam-Chen/Vue-Starter/blob/main/src/components/Table.vue this seems to work |
Describe the bug. A clear and concise description of what the bug is.
In recent versions, typing for the "row" value of slots changed, so now
row.item
is of typeTableItem
.That's per se correct (though it should be
TableItem<T>
) - but is causing some problems with typescript.To Reproduce. Steps to reproduce the behavior:
Expected behavior. A clear and concise description of what you expected to happen.
Functionality itself is working perfectly fine - but typechecking with vue-tsc fails with "unknown is not assignable to type number" (the actual type varies by prop).
The above code already contains the necessary cast (
(item as unknown as ComparisonItem)
) - but that's more than cumbersome - and defeats the purpose of using typescript.Is there any way to pass the type of the items to the table - so the component (and typescript) knows that the parameter for the slot is a
Tableitem<ComparisonItem>
- and has the type accordingly?TableItem itself knows about the type (
TableItem<T>
) - but the data comming back out doesn't.Screenshots. If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):
Additional context. Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: