I'm using React, Typescript and Swiper. I'm also on Shopify Hydrogen with server components. Which maybe preventing the files from finding the type definitions because creating a new Typscript app and installing Swiper doesn't have this issue.
我正在使用Reaction、TypeScrip和Swiper。我也在用服务器组件购物氢气。这可能会阻止文件找到类型定义,因为创建新的Typscript应用程序和安装Swiper没有这个问题。
Running "swiper": "^8.4.5",
react": "^18.2.0",
"@shopify/hydrogen": "^1.6.0",
正在运行“Swiper”:“^8.4.5”,REACT“:”^18.2.0“,”@Shopify/H2“:”^1.6.0“,
Property 'slidesPerView' does not exist on type 'IntrinsicAttributes & RefAttributes<SwiperRef> & SwiperProps'
类型“IntrinsicAttributes&RefAttributes
&SwiperProps”上不存在属性“”glidesPerView“”
It's not just slidesPerView, but other props as well.
这不仅仅是slidesPerView,还有其他道具。
Is there anything else I need to install?
I ran yarn add swiper
还有什么我需要安装的吗?我跑了纱线加雨刷
my component looks like.
我的组件看起来像。
import {Swiper, SwiperSlide, SwiperRef} from 'swiper/react'
// Import Swiper styles
import 'swiper/css'
return (
<Swiper
ref={swiperRef}
slidesPerView={3}
spaceBetween={30}
>
{slides.map((slide) => {
return (
<SwiperSlide key={slide.id}>
<Image ... />
</SwiperSlide>
)
})}
</Swiper>
更多回答
It's working for me in Create React App with your version of Swiper and React 18.
在你的Swiper和Reaction 18版本的Create Reaction App中,它对我很有效。
You're right, it works fine when I created a new app using create react app. I'm specifically using Shopify Hydrogen with server components. Which maybe causing the issue. I'll update my question. Thanks
你说得对,当我使用Create Reaction应用程序创建一个新应用程序时,它运行得很好。我专门在服务器组件上使用Shopify氢气。这可能是导致问题的原因。我会更新我的问题。谢谢
优秀答案推荐
Is there a solution on this case? I tried almost all the solutions but non of them worked. I'm working on create-react-app --template typescript. When I was working without --template typescript there was no problem like this.
这个案子有什么解决办法吗?我尝试了几乎所有的解决方案,但都没有奏效。我正在做创建-反应-应用程序--模板打字脚本。当我在没有模板打字的情况下工作时,没有这样的问题。
Update:
I SOLVED the problem. I downgraded the swiper from v10.0.4 to v9.4.1 and type problems gone. higher versions from v9.4.1 has these type problems. So I advise you guys to use lower versions of swiper.
更新:我解决了这个问题。我将Swiper从v10.0.4降级到v9.4.1,输入问题消失了。从V9.4.1起的更高版本存在这些类型问题。所以我建议你们使用较低版本的Swiper。
I found the solution to this problem. As discussed in this Github Issue the problem is the version of TypeScript. If you are under 5.1.6 version (I think is under 5) Swiper throw that error.
我找到了解决这个问题的办法。正如本期Github所讨论的,问题在于打字稿的版本。如果你的版本低于5.1.6(我认为低于5),Swiper就会抛出这个错误。
HOW TO FIX IT: Update TypeScript to 5.1.6 or above.
如何修复IT:将打印脚本更新到5.1.6或更高版本。
it's about versions!
这是关于版本的!
i decrease my swiper version to 9.4.1 and type script version to 5.2.2 and fixes issue,
我将Swiper版本降低到9.4.1,并键入脚本版本到5.2.2,并修复了问题,
hope helpful
希望对你有所帮助
write this to SwiperProps in swiper.react.d.ts file
将此内容写入Swiper.react.d.ts文件中的SwiperProps
slidesPerView:number,
spaceBetween:number,
pagination:{clickable:boolean},
modules:SwiperModule[]
It resolved my issue without downgrading to v9 of swiper
它解决了我的问题,而没有降级到Swiper的v9
npm i @types/swiper
or
或
yarn add @types/swiper
This is a stub types definition for @types/swiper (https://swiperjs.com).
这是@Types/Swiper(https://swiperjs.com).)的存根类型定义
swiper provides its own type definitions, so you don't need @types/swiper installed! reference
Swiper提供了自己的类型定义,因此您不需要安装@Types/Swiper!参考文献
更多回答
Had a similiar issue with the property "grabCursor", this solution worked like a charm.
对于属性“grabCursor”也有类似的问题,这个解决方案非常有效。
我是一名优秀的程序员,十分优秀!