[Flow.js中的SVG类型支持?

问题描述 投票:0回答:1

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

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

reactjs dom svg flowtype
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.