为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕斯709654 2023-10-17 16:56:02
我正在尝试将我的参数与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 接口,因为它未在库中导出。我不知道在这里做什么。
查看完整描述

1 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

如果你检查它的类型定义

https://github.com/Wufe/react-particles-js/blob/master/index.d.ts

export type IParticlesParams = RecursivePartial<{

  ...

}>


export interface ParticlesProps {

    width?: string;

    height?: string;

    params?: IParticlesParams;

    style?: any;

    className?: string;

    canvasClassName?: string;

}


type Particles = ComponentClass<ParticlesProps>;

因此导入类型IParticlesParams并使用它


import { Particles, IParticlesParams } from "react-particles-js";


let options: IParticlesParams = {

  ...

}

如果有任何进一步的类型错误,请像平常一样在文件中处理它就可以了


查看完整回答
反对 回复 2023-10-17
  • 1 回答
  • 0 关注
  • 47 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信