-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
implement Dev mode validation of {#each} block argument - disallow Sets, Maps, nonArrayLikes #4419
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
implement Dev mode validation of {#each} block argument - disallow Sets, Maps, nonArrayLikes #4419
Conversation
I, uh, also blogged about it in case you want this content somewhere |
I should also note that i went for two messages instead of one message because i wanted to make it abundantly clear that Svelte has considered allowing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. At some point it might be nice to provide support for Sets and Maps in an {#each}
, as it immediately seems like something that would be supported. This closes the gap until this functionality can be looked at.
- handle falsy {#each} arg - only mention spread if this is an iterable
closes #4408
Implemented two tests:
dev-warning-each-block-require-arraylike
:gets you the error:
Svelte needs an array-like value for the {#each} block. You can spread your iterable into an array instead, e.g. [...iterable]
dev-warning-each-block-no-sets-maps
:gets you the error:
Svelte does not allow Sets or Maps in an {#each} block. Use [...arg.values()] instead.
I'm not sure what other info to provide, happy to take input on what the wording of the error should be