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

Make entries in scopedSlots optional #15

Closed
wants to merge 1 commit into from

Conversation

thenickname
Copy link

With the current type definition TypeScript assumes that all scoped slots have to be provided. This makes it impossible to pass only one of multiple scoped slots.

This PR adjusts scopedSlots type to allow passing one or more scoped slots.

Before:

Due to the current type definition TypeScript complains that some of the slots are missing. This means, according to TypeScript you always have to pass all scoped slots. It is impossible to pass only one or some of them.

bildschirmfoto 2018-11-12 um 15 46 23

After:

ommiting some or all scoped slots is not an error anymore:

bildschirmfoto 2018-11-12 um 15 48 58

but passing some incompatible type still leads to an error message:

bildschirmfoto 2018-11-12 um 15 50 30

With the previous type definition TypeScript assumes that *all* scoped slots have to be provided. This makes it impossible to pass only one of multiple scoped slots.
@wonderful-panda
Copy link
Owner

Use yarn test before sending PR.

@thenickname
Copy link
Author

Hey, sorry for the breaking PR. I sent this PR as basis for discussion and hoped I would get some feedback about the solution. Why close this PR? I can improve the existing PR..

I ran yarn and then tried running yarn test. However, the command fails and I get no results about failing tests:

bildschirmfoto 2018-11-13 um 10 28 44

Is there anything else I have to install before running the tests?

Thanks.

@wonderful-panda
Copy link
Owner

you must run yarn build before yarn test.

BTW, I won't accept this PR because this approach breaks type-safety around scopedSlots.
Please consider another approach.

@thenickname
Copy link
Author

thenickname commented Nov 13, 2018

Thanks for your help.

I've taken a look at the breaking tests. I believe they are too strict and do not reflect how scoped slots are used in Vue.

My understanding of Vue slots in general is that they are not mandatory. They are optional. It's up to the component's author to render fallback content if a slot is not present at any given time. So it does not make sense for the type system to enforce the presence of every slot.

BTW I just recently got a PR accepted in Vue itself that reflects the fact that all slots are optional (reviewed and approved by Vue core members, but has yet to be merged): vuejs/vue#8946

this approach breaks type-safety around scopedSlots

While I must admit that a type like scopedSlots?: ScopedSlots<TScopedSlots> | { [key: string]: any } does look rather strange...it does seem be working correctly. And scopedSlots still are type safe after this change. It's just that they've become optional (which is the desired behavior).

The type checking still works, I believe.

I'm open to any suggestions for alternative solutions. But for now it seems to do the job without breaking type safety. It's just not useful to be forced to provide all the slots, especially if a component has a lot of them and providing them should be entirely optional.

Please bear with me if I'm missing something important...

@thenickname
Copy link
Author

thenickname commented Nov 13, 2018

I've updated the breaking tests, but the changes do not seem to be updated in this PR. I guess, it's because the PR is closed.

You can see the updated changes here: master...thenickname:master

I hope that you will consider this change...thanks!

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.

None yet

2 participants