Flow.js 是否支持 SVG 类型?

SVG types support in Flow.js?

我查看了各种 github threads,似乎 SVG 支持没有在 Flow.js 的当前版本中合并/发布(我使用的是 VS 代码扩展 vscode-flow-ide).我正在尝试使用 SVG 引用,现在不得不混合使用不太具体的类型 (Element) 和 // $FlowFixMe 来解决这些问题——从更广泛的类型安全角度来看并不理想.

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

临时解决方案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.
}

只键入方法和属性的子集比实现整个类型更容易。

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