wonderful-panda/vue-tsx-support

Improve ScopedSlot type

Closed this issue · 1 comments

Currently, scopedSlots are defined to accept a function that returns VNodeChildrenArrayContents | string:

// vnode.d.ts
export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | string;

So, acoording to the type definition a scoped slot function always has to return an array:

// scopedSlot callback:
renderSlotContent( props: ScopeProps ) {
      // must return array according to type definition:
      return ( [ <span>asdadsf</span> ] );
},

But, it is also possible to directly return an element / node without wrapping it in array:

// scopedSlot callback:
renderSlotContent( props: ScopeProps ) {
      // vue accepts this and it renders correctly
      return <span>asdadsf</span>;
},

At the same time typescript complains about this, because it assumes that the return type must be VNodeChildrenArrayContents | string.

Now, I have almost no knowledge about Vue render functions and VNodes and such...but why does the return type has to be an array? Is there a specific reason?

And, can that type definition be made more flexible so typescript stops complaining if the callback function returns a node directly (without wrapping it in an array)?

Thank you very much,
and thanks for this great library!

Already fixed