SVG types support in Flow.js?

前端 未结 1 1304

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-fl

1条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 10:40

    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.

    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.

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

    0 讨论(0)
提交回复
热议问题