fix incorrect parameters in event dispatching in Svelte #5716
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Svelte type definitions for custom events are declared as:
I couldn't find those in the sources, so I assume they're generated during the build process.
As you can see, an event handler subscribing to one of these events, should receive an array with either a single element (i.e. the swiper instance) or more parameters.
Theres a bug in the event delegation from Swipers internal state to Svelte at
swiper.svelte
. Instead of passing the original event parameters along, they're instead wrapped in another array. This is due to the fact of incorrect usage of the...args
spread parameter. The actual type is something likeCustomEvent<[[swiper: SwiperClass]]>
, right now.One problem arises, though, because this is sort of a breaking change. Project that currently rely on that misbehavior would break. If anyone used TypeScript and the definitions, they should've already noticed that.
I feel like this could also be checked in the CI. Unfortunately, you're not building svelte in the CI yet or at least on GitHub, as it seems. How do you feel about adding examples for all the integrations (e.g. Svelte, Vue and React) and then just build them as well to see if any warnings/errors are emitted. We could use the TypeScript compiler in "check" mode to spot any obvious type incompatibilities. The svelte template also ships with a handy check command, to verify all files.Only ifswiper.svelte
was strongly typed, this might be detectable by static checks.