swiper
swiper copied to clipboard
Thumbs property error when using TypeScript
Check that this is really a bug
- [X] I confirm
Reproduction link
https://codesandbox.io/s/swiper-thumbs-gallery-loop-vue-forked-eu064t?file=/src/App.vue
Bug description
Reproduction link is compiling even with lang="ts" set so it is just for representation of my swipers declaration. The same problem also happens with other props, such as :scrollbar or :mousewheel, and all of them disappear when script lang is set to js, not ts.
Expected Behavior
No response
Actual Behavior
Temporary solution:
initIconsSwiper(swiper:any){
this.iconsSwiper = swiper;
this.optionsSwiper.thumbs.swiper = this.iconsSwiper;
},
initOptionsSwiper(swiper:any){
this.optionsSwiper = swiper;
this.optionsSwiper.mousewheel.enable();
},
Swiper version
8.0.7
Platform/Target and Browser Versions
Windows, 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?
- [ ] I'm willing to open a PR
I'm seeing the same TypeScript error with the autoplay
prop while using Swiper 8.1.1, swiper/vue
and Nuxt 3 (RC):
(property) autoplay?: undefined
Type '{ delay: number; }' is not assignable to type 'undefined'.ts(2322)
Here is a very simple demo: https://github.com/luvejo/swiper-ts-issue
Steps to reproduce
- Clone the repo and open it with VS Code.
- Make sure you have Volar installed.
- Open
app.vue
and you'll see the error at line 13.
Platform/Target and Browser Versions
- OS: Ubuntu 21.10
I'm having the exact same problem in react with typescript...
Seems that there's this .destroyed
property that must be checked... the following line worked for me (react):
thumbs={{swiper: thumbsSwiper && !thumbsSwiper.destroyed ? thumbsSwiper : null}}
ref: https://stackoverflow.com/questions/73046820/swiper-react-cannot-convert-undefined-or-null-to-object
Swiper v9 comes with fully reworked and now different loop functionality. If you have similar issues in Swiper 9, open a new issue with a CodeSandbox showing the issue.