swiper icon indicating copy to clipboard operation
swiper copied to clipboard

Thumbs property error when using TypeScript

Open kamilmedrala opened this issue 2 years ago • 3 comments

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

image

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

kamilmedrala avatar Mar 11 '22 18:03 kamilmedrala

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

  1. Clone the repo and open it with VS Code.
  2. Make sure you have Volar installed.
  3. Open app.vue and you'll see the error at line 13.

Platform/Target and Browser Versions

  • OS: Ubuntu 21.10

larxn avatar Apr 20 '22 02:04 larxn

I'm having the exact same problem in react with typescript...

Enzodtz avatar Sep 04 '22 20:09 Enzodtz

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

Enzodtz avatar Sep 04 '22 20:09 Enzodtz

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.

nolimits4web avatar Feb 01 '23 11:02 nolimits4web