如何从 React-Particles-JS 库导入此接口?

我正在尝试将我的参数与react-articles-js 库中的JSX 分开。我将参数放在一个对象中:


let options = {

        "particles": {

            "number": {

                "value": 50

            },

            "size": {

                "value": 3

            }

        },

        "interactivity": {

            "events": {

                "onhover": {

                    "enable": true,

                    "mode": "repulse"

                }

            }

        }

    }


然后我写我的 JSX:


<Particles params={options}/>

当我这样做时,我收到错误


The types of 'interactivity.events.onhover.mode' are incompatible between these types.

    Type 'string' is not assignable to type '"repulse" | "grab" | "push" | "remove" | "bubble" | InteractivityMode[] | undefined'.  TS2322

我无法导入 InteractivityMode 接口,因为它未在库中导出。我不知道在这里做什么。


慕斯709654
浏览 51回答 1
1回答

慕森卡

如果你检查它的类型定义https://github.com/Wufe/react-particles-js/blob/master/index.d.tsexport type IParticlesParams = RecursivePartial<{&nbsp; ...}>export interface ParticlesProps {&nbsp; &nbsp; width?: string;&nbsp; &nbsp; height?: string;&nbsp; &nbsp; params?: IParticlesParams;&nbsp; &nbsp; style?: any;&nbsp; &nbsp; className?: string;&nbsp; &nbsp; canvasClassName?: string;}type Particles = ComponentClass<ParticlesProps>;因此导入类型IParticlesParams并使用它import { Particles, IParticlesParams } from "react-particles-js";let options: IParticlesParams = {&nbsp; ...}如果有任何进一步的类型错误,请像平常一样在文件中处理它就可以了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5