SVG types support in Flow.js?

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.

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

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply