Flow.js是否支持SVG类型? [英] SVG types support in Flow.js?

查看:57
本文介绍了Flow.js是否支持SVG类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've looked around at various github threads and it seems as if SVG support is not merged / shipped in current versions of Flow.js (I'm using VS Code extension vscode-flow-ide). I'm trying to work with SVG refs and for now have had to use a mix of less-specific type (Element) and // $FlowFixMe to work around these - not ideal from a broader type-safety perspective.

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

Anyone solved this? I'm using /flow/lib/dom.js currently, but it lacks these types.

推荐答案

Interrim解决方案直到正式列入清单为止 ...

Interrim solution until the official inclusions are made...

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

For types that are missing, implement your own for that subset of properties that you intend to use.

例如,我正在处理SVG,因此在文件 SVGElement.js.flow (以

For example, I am manipulating SVGs, so in a file SVGElement.js.flow (named after the 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.
}

仅键入方法&的子集属性比必须实现整个类型更容易.

Typing only subsets of methods & properties is easier than having to implement the entire type.

& 允许从/flow/lib/dom.js 中存在的 HTMLElement 继承;参见交叉点类型.

The & allows inheritance from HTMLElement present in /flow/lib/dom.js; see intersection types.

这篇关于Flow.js是否支持SVG类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆