【问题标题】:SVG types support in Flow.js?Flow.js 中的 SVG 类型支持?
【发布时间】:2020-04-22 00:07:34
【问题描述】:

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

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

【问题讨论】:

    标签: reactjs dom svg flowtype


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      • 2019-08-24
      • 2021-05-26
      • 2020-04-13
      • 2011-04-22
      相关资源
      最近更新 更多