Skip to content
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

Improve ScopedSlot type #11

Closed
thenickname opened this issue Oct 13, 2018 · 1 comment
Closed

Improve ScopedSlot type #11

thenickname opened this issue Oct 13, 2018 · 1 comment

Comments

@thenickname
Copy link

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!

blake-newman added a commit to blake-newman/vue-tsx-support that referenced this issue Dec 11, 2018
- Update vue dependencies
- Fix scoped slots definitions to be compatible with Vue typings
- ScopedSlots can be undefined as there is no guarantee that the scoped
slot has to be passed. vuejs/vue@448ba65
- Fixes wonderful-panda#11
blake-newman added a commit to blake-newman/vue-tsx-support that referenced this issue Dec 11, 2018
- Update vue dependencies
- Fix scoped slots definitions to be compatible with Vue typings
- ScopedSlots can be undefined as there is no guarantee that the scoped
slot has to be passed. vuejs/vue@448ba65
- Fixes wonderful-panda#11
@wonderful-panda
Copy link
Owner

Already fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants