Skip to content

type SwiperOption can't assign to Swiper Component #8026

Open
@ItsuoSano

Description

@ItsuoSano

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/p/devbox/dkhjfc?file=%2Fsrc%2FApp.vue%3A10%2C32

Bug description

type SwiperOptions (import from swiper/types) can't assign Swiper (import from swiper/vue) as options.

some options are not have null.

in type definition

width?: number | null;

so width is number | null | undefined

in component

width: { type: Number, default: undefined },

width is number | undefined

Expected Behavior

change to

width: { type: [Number, null] , default: undefined }, 

Actual Behavior

<script setup lang="ts">
import type { SwiperOptions } from 'swiper/types'
import { Swiper } from 'swiper/vue'

const options: SwiperOptions = {}
</script>

<template>
  <div>
    <Swiper v-bind="options" /> 
<!-- 
Types of property 'width' are incompatible.
      Type 'number | null | undefined' is not assignable to type 'number | undefined'.
        Type 'null' is not assignable to type 'number | undefined'.
-->
  </div>
</template>

Swiper version

"11.2.8"

Platform/Target and Browser Versions

VScode + Vue(Official)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions