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

[fix] scoped slot typing #17

Closed

Conversation

blake-newman
Copy link
Contributor

  • 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 Improve ScopedSlot type #11

- 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
@chanlito
Copy link

Hey @blake-newman just out of curiosity which version of typescript are you on?

@blake-newman
Copy link
Contributor Author

This will be the latest version 3.1.2 for our projects.

This project uses: https://github.com/wonderful-panda/vue-tsx-support/blob/master/package.json#L56

- ScopedSlots return value was updated
- ScopedSlots return value is now exposed in 2.5.21 so use this export
@wonderful-panda
Copy link
Owner

I don't want to make all scoped slots optional unconditionally.

I think it would be better that optional slots are marked explicitly like below.

export interface MyScopedSlots {
  foo?: string;  // optional
  bar: string; // required
}

export const MyComponent = tsx.componentFactoryOf<{}, MyScopedSlots>().create({
  render(): VNode {
    const { foo, bar } = this.$scopedSlots;
    return (
      <div>
        { foo ? foo("foo") : "default foo" }
        { bar("bar") }
      </div>
    );
  }
});

@blake-newman
Copy link
Contributor Author

That makes sense, aslong as the usage (<Component scopedSlots={{...}} />) enforces that scoped slots must be passed if declared. This way you can't run into a runtime error with scoped slots.

Do you know if this is currently the case? I will amend this PR to make the typing more strict.

@wonderful-panda
Copy link
Owner

@blake-newman
Sorry for the late response.

Currently vue-tsx-support enforces to specify all declared scoped slots as you said.
Vue itself allows scoped slots to be omitted.
It would be nice that vue-tsx-support can support scoped slots omitting, but I don't want to spoil current type-safety to support it.

BTW, I pushed and published as v2.2.2 related change to fix #18, (7f277c8). Vue 2.5.13 is still supported.
I don't think we must support Vue 2.5.13, it is old enough, but I think we should support not only Vue 2.5.21 (newest), but also several older versions as possible.

@blake-newman blake-newman deleted the fix/scoped-slots branch October 23, 2019 07:39
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 this pull request may close these issues.

Improve ScopedSlot type
3 participants