Skip to content
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

The type of snapIndex does not exist in type Swiper #5733

Closed
6 tasks done
hiroya-uga opened this issue May 20, 2022 · 0 comments
Closed
6 tasks done

The type of snapIndex does not exist in type Swiper #5733

hiroya-uga opened this issue May 20, 2022 · 0 comments
Labels

Comments

@hiroya-uga
Copy link

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/s/swiper-pagination-react-forked-bdgf3d?file=/src/App.jsx

Bug description

The type of snapIndex does not exist in type Swiper.
In fact, it is any, despite the fact that it is a number.

Developers need to add the following code to global.d.ts to use snapIndex.

declare module 'swiper' {
  interface Swiper {
    snapIndex: number;
  }
}

* It is not present by default. When updateIndex is called, the snapIndex property appears by Object.assign.
https://github.com/nolimits4web/swiper/blob/master/src/core/update/updateActiveIndex.js#L55-L60
* It does not exist in document. But snapIndexChange exists.
https://swiperjs.com/swiper-api#event-snapIndexChange

Expected Behavior

TypeScript knows type of snapIndex as number.

Actual Behavior

TypeScript does not know type of snapIndex as number. It knows as any.

Swiper version

8.1.3

Platform/Target and Browser Versions

macOS 12.3.1 Visual Studio Code latest

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant