Flow.js是否支持SVG类型?

时间:2020-01-03 12:06:55

标签: reactjs dom svg flowtype

我到处查看了各种github thread,似乎在当前版本的Flow.js中没有合并或提供SVG支持(我正在使用VS代码扩展vscode-flow-ide)。我正在尝试使用SVG引用,并且现在不得不使用不太特定的类型(Element)和// $FlowFixMe的组合来解决这些问题-从更广泛的类型安全角度来看,这不是理想的选择

有人解决了吗?我目前正在使用/flow/lib/dom.js,但缺少这些类型。

1 个答案:

答案 0 :(得分:0)

Interrim解决方案until the official inclusions are made ...

对于缺少的类型,为要使用的属性子集实现自己的类型。

例如,我正在处理SVG,因此在文件SVGElement.js.flow(以DOM type命名)中:

type SVGElement = HTMLElement & 
{
    fonts: [],
    fillOpacity: number
    //...
    //In reality, SVGElement has many more properties, but you can include  
    //only those you will use and which thus require type-safety.
    //You can add whatever you need, incrementally, as time passes.
}

仅键入方法和属性的子集比必须实现整个类型要容易。

&允许从HTMLElement中存在的/flow/lib/dom.js继承;参见intersection types