-
-
Notifications
You must be signed in to change notification settings - Fork 371
feat: add optional Data generic type for VueFlow container component
#1992
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
feat: add optional Data generic type for VueFlow container component
#1992
Conversation
…n VueFlow component
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
|
@nevehallon is attempting to deploy a commit to the Burak Cakmakoglu's projects Team on Vercel. A member of the Team first needs to authorize it. |
VueFlow container component
VueFlow container componentData generic type for VueFlow container component
|
thank you for the PR, appreciate it. |
|
Here is a v1 workaround — not ideal, not exhaustive, but might be useful until v2 lands: import { VueFlow } from '@vue-flow/core';
import type { Elements, Node, NodeProps } from '@vue-flow/core';
import type { DefineComponent, SlotsType } from 'vue';
// Define your custom data interfaces
interface CustomData {
label: string
count: number
}
interface CustomData2 {
label2: string
count2: number
}
// Define your specific Node types
type MyCustomNode = Node<CustomData, any, 'custom'>
type MyCustomNode2 = Node<CustomData2, any, 'custom2'>
type FlowNodeUnion = MyCustomNode | MyCustomNode2
type FlowNodeType = 'custom' | 'custom2'
// Define the Slots you want to strictly type
type MyCustomSlots = {
'node-custom': (props: NodeProps<CustomData, any, 'custom'>) => any
'node-custom2': (props: NodeProps<CustomData2, any, 'custom2'>) => any
}
/**
* ---------------------------------------------------------------------
* MONKEY PATCH
* ---------------------------------------------------------------------
*/
type OgVueFlowComponentT = typeof VueFlow
type OgVueFlowInstanceT = InstanceType<OgVueFlowComponentT>
type PropsWithOverrides = OgVueFlowInstanceT['$props'] & {
nodes?: Node<FlowNodeUnion['data'], any, FlowNodeType>[];
modelValue?: Elements<FlowNodeUnion['data']>;
}
type SlotsWithoutOverrides = OgVueFlowInstanceT['$slots'] & SlotsType<MyCustomSlots>
type VueFlowTypedOverload = OgVueFlowComponentT &
DefineComponent<
PropsWithOverrides,
{},
{},
{},
{},
{},
{},
{},
string,
{},
{},
{},
SlotsWithoutOverrides
>
export const VueFlowWithTypedSlots = VueFlow as VueFlowTypedOverload |
|
Thanks for posting a workaround =) |
🚀 What's changed?
VueFlowcomponent using Vue 3.3+genericattribute (<script setup generic="Data = ElementData">).VueFlow, enabling strict typing and IntelliSense for element data within the template (e.g., in scoped slots).Example Usage:
🐛 DX
modelValue,nodes,edges)🪴 To-Dos
nodesandedgesprops instead of requiring explicit definition.CustomEventsandType)