我正在嘗試將我的參數與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 = {
...
}
如果有任何進一步的類型錯誤,請像平常一樣在文件中處理它就可以了
- 1 回答
- 0 關注
- 107 瀏覽
添加回答
舉報
0/150
提交
取消