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

return type of scopedSlots.foo({}) doesn't match the return type of render() in functional components #10266

Closed
jacekkarczmarczyk opened this issue Jul 14, 2019 · 2 comments

Comments

@jacekkarczmarczyk
Copy link

jacekkarczmarczyk commented Jul 14, 2019

Version

2.6.10

Reproduction link

https://jsfiddle.net/1yonhcvb/

Steps to reproduce

import Vue, { VNode } from 'vue';

// Works
Vue.extend({
  functional: true,
  render: (h, { scopedSlots }) => scopedSlots.default({}) as VNode[],
});

// Doesn't work
Vue.extend({
  functional: true,
  render: (h, { scopedSlots }) => scopedSlots.default({}),
});

What is expected?

I should be able to return scoped slot without casting

What is actually happening?

I need to cast scoped slot return value to VNode[], otherwise it results in TS error:

Argument of type '{ functional: boolean; render: (h: CreateElement, { scopedSlots }: RenderContext<Record<never, any>>) => ScopedSlotChildren; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'.
  Object literal may only specify known properties, and 'functional' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'.ts(2345)

Might be related to #9372

@jacekkarczmarczyk jacekkarczmarczyk changed the title return type of scopedSlots.foo({}) doesn't match the return value of render() in functional components return type of scopedSlots.foo({}) doesn't match the return type of render() in functional components Jul 14, 2019
@posva
Copy link
Member

posva commented Jul 14, 2019

Since the scopedSlots can return undefined, you need to guard against that:

const Testy: FunctionalComponentOptions = {
  functional: true,
  render: (h, { scopedSlots }) => scopedSlots.default({}) || h(),
}

Vue.extend({
  functional: true,
  render: (h, { scopedSlots }) => scopedSlots.default({}) || h(),
})

@jacekkarczmarczyk
Copy link
Author

Thank you

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

No branches or pull requests

2 participants