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

Controller type error issue in Swiper in React typescript environment #6505

Closed
6 tasks done
TakhyunKim opened this issue Mar 19, 2023 · 0 comments
Closed
6 tasks done
Labels

Comments

@TakhyunKim
Copy link
Contributor

TakhyunKim commented Mar 19, 2023

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/s/react-typescript-forked-8mg7tl?file=/src/App.tsx

Bug description

Thanks for the great library.

Type error occurs when using controller function in React, typescript environment.
Controller docs assign null as the useState value first.
However, if you end up assigning null, you will get the type error below.

Type 'null' is not assignable to type 'string | Swiper | HTMLElement | Swiper[] | undefined'.

Using a non-null undefined in the React 17 environment will cause the type error, and it works just fine.

error

Expected Behavior

Assigning null will not cause a type error.

Actual Behavior

null, an error is raised.

I think there are two solutions.

  1. add null to the control type and see if it works
  2. modify the code in the swiper React Controller docs example

Swiper version

9.1.1

Platform/Target and Browser Versions

mac OS, chrome

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