-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Using defineSlots with dynamic slot names causes error TS2349: This expression is not callable. #2758
Comments
There were multiple problems in this use case, some fixed by Volar: Others need to wait for upstream fixes, or changes to your code.
- <template v-for="(value, key) of itemData">
+ <template v-for="(value, key) of props.itemData"> - defineProps<{
+ const props = defineProps<{
itemData: T;
}>(); Upstream issue: vuejs/core#8144
- [K in keyof T as K extends string ? `cell:${K}` : never]: { value: T[K] };
+ [K in `cell:${string}`]: { value: T[keyof T] }; |
Glad the comments have been reopened so that I can reply again!
@johnsoncodehk E.g.: This is a regression from version 1.2, and I hope it can be supported again. |
This is due to the limitation caused by supporting short definitions of slots, we removed it in #3116, you need to modify your component code accordingly, FYI this is the complete modified code: <template>
<div>
<slot />
<template v-for="(value, key) of props.itemData">
<slot
v-if="typeof key === 'string'"
:name="`cell:${key}`"
:value="(value as T[string])"
/>
</template>
</div>
</template>
<script lang="ts" setup generic="T extends DataType">
export type DataType = Record<string, string>;
defineSlots<
{
[K in keyof T as K extends string ? `cell:${K}` : never]?: (_: { value: T[K] }) => any;
} & {
default?: (_: Record<string, any>) => any;
}
>();
const props = defineProps<{
itemData: T;
}>();
</script> |
But how could I preserve the order of items from input object if I want 'a' come after 'b'? |
I have a generic component, where the slots are defined by the keys of the object bound to the generic parameter.
This is a simplified version of such a component:
MyComp.vue
And it can be used like this:
App.vue
Up to version 1.2 the typechecking in App.vue was working fine, the slots names were recognized and so was the type of the scope variables.
Since the vue-tsc update that validates the slots in the component that defines them, I am now getting the following errors:
Reproduction: Stackblitz
The text was updated successfully, but these errors were encountered: