swiper
swiper copied to clipboard
TypeScript error: autoplay doesn't accept AutoplayOptions object
Check that this is really a bug
- [X] I confirm
Reproduction link
https://swiperjs.com/swiper-api#autoplay
Bug description
When I use swiper in a svelte typescript project, I cannot use the autoplay prop as intended.
Swiper autoplay
prop only accepts boolean
instead of boolean | AutoplayOptions
.
I've been digging a bit in the source files and it looks like these lines in svelte.d.ts
seem to be the problem:
4 // @ts-ignore
5 interface SwiperProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap['div']> {}
6 interface SwiperProps extends SwiperOptions {}
Changing the lines to
4 interface SwiperProps extends SwiperOptions, svelte.JSX.HTMLAttributes<HTMLElementTagNameMap['div']> {}
Resolves the warning and gives me autocomplete hints.
Expected Behavior
I am able to pass an AutoplayOption
object to the autoplay
prop as described in the docs.
<Swiper
autoplay={{
delay: 1337,
pauseOnMouseEnter: true
}}
>
…
Actual Behavior
Throws TS error:
Type '{ delay: number; pauseOnMouseEnter: boolean; }' is not assignable to type 'boolean'.
.
Swiper version
8.0.7
Platform/Target and Browser Versions
macOS, Chrome
Validations
- [X] Follow our Code of Conduct
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
- [X] Make sure this is a Swiper issue and not a framework-specific issue
Would you like to open a PR for this bug?
- [X] I'm willing to open a PR
I got the same problem that I have to type the autoplay object as any
before passing as prop to get away with it. It shouldn't be this way.
I also encountered this. v8.4.2
Still an issue in 8.4.6, but I opened a PR with the suggested change: #6294.